joomla-extensions / jedchecker

Joomla extension to check components, modules or plugins for possible problems for submission to the JED -> Translations: https://joomla.crowdin.com/joomla-official-extensions
38 stars 28 forks source link

Error: Whitespace in the key is not allowed #191

Closed jschmi102 closed 6 months ago

jschmi102 commented 1 year ago

I've considered to offer my extension, which runs since joomla 3.0 now also with joomla 4.2RC1 without any problems. to the JED. So I ran a check with JED-Checker and I was quite surprised that the checker qualified my extension to be in error caused by "whitespace in the language key". But first let me explain why my extension is using white spaces in language keys with Joomla's very powerful multilanguage support. My extension retrieves country info from geolocation server, which e.g. provide county names and county codes. Country names are only provided in english language. To display those names also in german language, joomla multi lanaguage support ist used.

So If I get:

  $country['name'] = "Bosnia and Herzegovina" or
  $country['name'] = "Austria"

I'm using Joomla's TEXT-function: echo Text::_($country['name']); to display the country name.

The TEXT-function will cause Joomla to lookup for a language key "BOSNIA AND HERZEGOVINA" or 'AUSTRIA' (upper case of key). But as Joomla will not find this key, it will display instead the original key as key-value. So you will see a display showing Bosnia and Herzegovina and Austria

But now if you add to your used ("de-DE") language ini file the entry:

BOSNIA AND HERZEGOVINA="Bosnien und Herzegovina"
AUSTRIA="Östereich"

You will see the correct display on your german site "Bosnien und Herzegovina" and "Östereich"

You see "whitespace in the language key" is not a restriction it works perfectly and I do not see any reason why to avoid it and I do not see a better solution than mine for this. Can you please explain, why you classify this as error (or is JED checker doing wrong and will be corrected)?

dryabov commented 1 year ago

First, I'd like to note that JEDChecker issues a warning, not an error.

Actually, there are two problems with your approach:

1) Joomla uses a single registry for translations, so one extension can overwrite strings of another extension. For example, one extension may translate "Czech" to "Tscheche" for de-DE locale, but the other does it to "Tschechin" or "Tschechisch". As a solution to this problem, it is highly recommended to use language keys with a unique prefix (e.g. COM_MYEXTENSION__COUNTRY_CZECH), but this, in turn, means that situations, where Joomla outputs the original key, should not occur. A standard approach to solve the problem, when the translation file does not contain some values, is to load the English translation file and then the current language translation file to overwrite values. If I'm not mistaken, in Joomla 3.2+ it is done automatically, and in older Joomla versions it had to be done manually.

2) Translators may use third-party utilities to work with ini-files, and I'm not sure all of them support keys with spaces. For convenience, it is better to use a common denominator of avoiding PHP-specific things there (i.e., spaces in keys, the injection of constants into string values ​​via ${CONST}, etc.).

jschmi102 commented 1 year ago

JEDchecker clearly issues an error (message even is color coded in red): grafik I cannot folllow your arguments if an extension uses the joomla language interface correctly there may not be any collision - on the other hand I'm using only common country names (iso standard names), which cannot cause wrong translation. (e. g. "Germany" will always translate to "Deutschland")

I'm seeing these facts for my implementation:

My implementation for german language support (as used right now) needs only 3 lines of code plus some entries in a language ini-file. Therefore I think it would be silly to comletely change design and coding only to make JEDChecker happy.

dryabov commented 1 year ago

Hmm, I've found original reason to make it error. There was the Specification of language files page on docs.joomla.org with the following requirements:

  1. The KEY is now defined to be
    • without any whitespace. All whitespace shall be converted into a underscore '_'
    • All KEY's in the frontend shall include a prefix of the extension

I don't know why this page was removed without a replacement.

PS. My opinion is that, in general, all rules except of "core" ones (Info, License, XML Manifests, XML Files, GPL License) should trigger warnings instead of errors. But at the same time I think that "error" is a proper level in this particular case: using of a raw text instead of a prefixed keys in language file is ok for local development, but not for JED, because it may lead to conflicts between different extensions.