moodlehq / moodle-cs

Moodle Coding Style
https://github.com/moodlehq/moodle-cs
GNU General Public License v3.0
18 stars 15 forks source link

Warning: The string key "y" is not in the correct order, it should be before "x" #149

Closed gjb2048 closed 5 months ago

gjb2048 commented 5 months ago

In version https://github.com/moodlehq/moodle-cs/releases/tag/v3.4.6, there are now the warnings about the language strings not being in the correct order, such as:

Screenshot 2024-04-03 125344

This is because with the amount of strings in the plugin, I order them alphabetically within groups that relate to the functional areas that they belong.

Therefore can this be taken into account or removed? As duplicates are reported in any event.

andrewnicols commented 5 months ago

You can disable the sniff by either disabling the specific rule:

// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder -- Allow lang files to be in any order.

Or all sniffs:

// phpcs:disable moodle.Files.LangFilesOrdering -- Ignore all lang file ordering checks.

You may also want to disable the moodle.Files.LangFilesOrdering.UnexpectedComment sniff if you put comments on each section.

gjb2048 commented 5 months ago

Thanks @andrewnicols that's really helpful :)

andrewnicols commented 5 months ago

Okay, I'll close this issue now then. If you think this is wrong, please comment and I'll reopen.

mudrd8mz commented 5 months ago

@gjb2048 just note that translators using AMOS will see the strings ordered by stringid anyway. It often helps to keep related strings together so that the context of the translation is easier to understand. To keep related strings together, it is wise to have them named sharing same prefix, as in

$string['foobar'] = 'Do you want to ...';
$string['foobarno'] = 'No, I prefer to ...';
$string['foobaryes'] = 'OK, let us ...';

That way, you can have them grouped together both in native PHP as well as in the translation tools. That was one of the reasons to have this sniff implemented.

gjb2048 commented 5 months ago

@mudrd8mz I do within the functional groups, i.e. https://github.com/gjbarnard/moodle-format_topcoll/blob/main/lang/en/format_topcoll.php (which does actually needs to be tidied) - but also don't want to mix up the different functional areas for ease of maintenance reasons.

mudrd8mz commented 5 months ago

Fair enough. I only wanted to explain the reasoning behind this. All good, thanks Gareth.

gjb2048 commented 5 months ago

@mudrd8mz No worries and thank you. Just now wondering if there should be full support of 'grouping of language strings' in AMOS then would perhaps bring better context to translators if they understood more about the functionality that the strings relate to. In addition, could then break down the translation process into manageable time blocks with a defined goal of a 'group' per translation session.

mudrd8mz commented 5 months ago

Interesting idea, thanks!