Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Whitespace in the key is not allowed #191

Closed
jschmi102 opened this issue Aug 13, 2022 · 3 comments
Closed

Error: Whitespace in the key is not allowed #191

jschmi102 opened this issue Aug 13, 2022 · 3 comments

Comments

@jschmi102
Copy link

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
Copy link
Collaborator

dryabov commented Aug 13, 2022

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
Copy link
Author

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:

  • php does not report any errors, warnings or notices
  • joomla does not report any errors, warnings or notices
  • my extension (module) successfully uses the design of joomla's multi-language support (no errors, no warnings)
  • sofar I did not find any joomla docs saying "white space in language keys is not allowed"

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
Copy link
Collaborator

dryabov commented Aug 14, 2022

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.

@dryabov dryabov closed this as completed Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants