Strings beginning with space

Strings beginning with space

by Séverin Terrier -
Number of replies: 8

Hi,

I open this discussion after seeing a problem on badge page (in french).

After some search, it appears that some (english) strings begin with (a) space. And when one wants to insert this space in existing translation, AMOS ignores it, don't see the change, and it's impossible to insert this space.

I've made a search on Moodle 3.8 code, with the following command (from Moodle directory):

for i in `find . -type f -name '*.php' | grep 'lang/en/'`
do grep -Hne "'] = ' " $i | grep string
done | sort | cut -c 3-

and results are:

admin/tool/lp/lang/en/tool_lp.php:211:$string['sitedefault'] = ' (Site default) ';
lang/en/admin.php:768:$string['maxusersperpage'] = ' Maximum users per page';
lang/en/badges.php:170:$string['bydate'] = ' complete by';
lang/en/badges.php:199:$string['criteria_descr_bydate'] = ' by <em>{$a}</em> ';
lang/en/badges.php:200:$string['criteria_descr_grade'] = ' with minimum grade of <em>{$a}</em> ';
lang/en/badges.php:555:$string['warnexpired'] = ' (This badge has expired!)';
lang/en/repository.php:74:$string['confirmrenamefolder'] = ' Are you sure you want to move/rename this folder? Any alias/shortcut files that reference files in this folder will be converted into true copies.';
question/type/calculated/lang/en/qtype_calculated.php:49:$string['datasetrole'] = ' The wild cards <strong>{x..}</strong> will be substituted by a numerical value from their dataset';

If you search with several installed plugins, you'll find other strings.

Moreover, i'm wondering if these spaces shouldn't better be defined in Moodle code than in lang strings? Is there a recommandation/coding style? I don't find anything clear about this in coding style documentation.

Séverin


In reply to Séverin Terrier

Re: Strings beginning with space

by koen roggemans -
Picture of Language pack maintainers

I wonder if all the spaces are required. If not, I would expect to see nothing special on the page, since two spaces become one in the rendering of html in the browser. If they are required, all translations should look ugly, since no translated language pack can have the space there. 

In the first case I would say it's ugly from a technical point of view, but harmless. In the second case I would file it as a bug (one per string I guess).

In reply to koen roggemans

Re: Strings beginning with space

by Séverin Terrier -

I must admit i'm not sure if all spaces are needed, but for sure some are.

You can look at screenshots in the french discussion i pointed to better understand: the problems are not double spaces (ignored by HTML rendering) but missing spaces.

Choice has been made to integrate them in strings rather than in Moodle code, and i wonder if it's the right way of doing it, and if there are recommandations about that.

In fact, when looking at translations, some (rare) have beginning space, and most not. If you launch, from moodledata/lang folder the command grep criteria_descr_bydate */badges.php | grep "'] = ' " you'll see that de and hr languages have beginning space, but most languages not.

I just don't know if AMOS doesn't allow beginning space, or if it just don't see the difference beetween previous existing string without space and the new one with space. If it's the case, perhaps it could be possible that the language maintener modify the string, and validate it, to be able to modify it again, adding space.

Even if it's possible that way, i still wonder if it shouldn't better be directly encoded.

Séverin

In reply to Séverin Terrier

Re: Strings beginning with space

by koen roggemans -
Picture of Language pack maintainers

It's a no brainer: there shouldn't be any leading or trailing spaces required in translation because it's too error prone.

In reply to koen roggemans

Re: Strings beginning with space

by Nicolas Martignoni -
Picture of Language pack maintainers

I completely agree. I suggest to amend the Coding Style documentation page to clarify this and add an example under "Language strings > Structure": https://docs.moodle.org/dev/Coding_style#Language_strings.

Is there some procedure to follow (e.g. "policy" issue to open, as this is a quite official document) or can I do it directly?

In reply to Nicolas Martignoni

Re: Strings beginning with space

by David Mudrák -
Picture of Language pack maintainers

Yes, there is a procedure - please report such a suggestion as a new MDL issue, component "Policy".

I agree it is a bad practice to design strings with trailing and heading whitespace and I believe it should be considered a bug in the original English strings.

Meanwhile, you should be able to insert strings with whitespaces into AMOS though - https://lang.moodle.org/mod/forum/discuss.php?d=5908#p6932

In reply to David Mudrák

Re: Strings beginning with space

by Séverin Terrier -

Thanks David for (pointing to) the tip : Maintaining CTRL before clicking on text editing place to avoid AMOS filtering smile

Here's a command to search for english files containing trailing space (launch from Moodle dir) :

for i in `find . -type f -name '*.php' | grep 'lang/en/'`
  do grep -Hne " ';$" $i | grep string
done | sort | cut -c 3-

There are more than for begining space. I suppose my search won't find multiple lines strings...

Séverin

In reply to David Mudrák

Re: Strings beginning with space

by Nicolas Martignoni -
Picture of Language pack maintainers

Just a notice about AMOS: it's impossible to propagate strings with leading spaces to other versions (or at least I didn't find how to).

Is it worth opening an tracker issue?