Instead of just using the first supported language, look at all the preferred ones, trying to return one for which the language file exists. And if we have none, just return the first one.
This solves the problem where your project has localized something else in a region specific language, but still want to use the a general language (without region) for the base translations.
For Example:
You localize fr-FR on one file that should be specific to France.
But you still want to use fr.json for the base translations.
This will try to grab fr-FR.json, but if it doesn't exist will use fr.json, assuming that is another supported language in your project.
Instead of just using the first supported language, look at all the preferred ones, trying to return one for which the language file exists. And if we have none, just return the first one.
This solves the problem where your project has localized something else in a region specific language, but still want to use the a general language (without region) for the base translations. For Example:
fr-FR
on one file that should be specific to France.fr.json
for the base translations.fr-FR.json
, but if it doesn't exist will usefr.json
, assuming that is another supported language in your project.