BoltTranslate / labels

Bolt Labels extension - Translatable labels for Bolt
https://bolt.cm/
18 stars 12 forks source link

4 / 5 letter language codes #41

Open MarienTimOnline opened 7 years ago

MarienTimOnline commented 7 years ago

Hi there. The docs state:

"It's advisable to stick to two-letter language codes."

That would be fine normally, but a client has customers in different countries where language-difference within the base language actually matters.

So I really need 'de-DE' and 'de-CH' on this one (for example).

How can I achieve this? I believe the code of the extension itself only wants to check on 2 digits.

bobdenotter commented 7 years ago

Have you tried using de and ch to differentiate between the two?

MarienTimOnline commented 7 years ago

I did, and that broke the whole translation principle.

In vendor/bolt/labels/src/LabelsExtension.php line 93 you can actually see the extension cutting back to the '2 digit version'

Set the current language, always based on a 2-letter code

$lang = substr($request->getLocale(), 0, 2);

bobdenotter commented 7 years ago

Hmm. Do you have a suggestion on how to fix this?

MarienTimOnline commented 7 years ago

Well in a functional sense the code should count the digits. If the label (the label's label) is 2 digits long, then the first part of the 'locale' can be matched. If the label is 2+ digits (nl-NL, but also nl_NL) it should try to match 5 digits of the locale.

In a technical sense, all relevant code seems to be in LabelsExtension.php.

Somehow the extension would need to 'allow' for 2 OR 5 digit languagecodes. Of course, the admin would need to use one or the other in the labels matrix... or things might break.