Localisation Library
nibra opened this issue · 4 comments
Library to localise strings
Requirements
-
Current language files MUST be re-usable.
A lot of efford has been put into translations into a vast number of languages. It does not make sense to discard that work.
-
Admin MUST be able to define a fallback, ideally a fallback cascade.
Example: If the current language is Swedish, use Danish for missing translations. If there's no Danish translation, too, use English instead.
-
Language definitions MUST be overrideable.
Wording and phrases are often changed to match the style of the site. Those changes must not be reverted on updates.
-
The call of the translation function SHOULD have a very small footprint.
A short notation is preferred. The
gettext
function_('foo')
is ideal in this regard. A construct like$languageManager->translate('foo')
is too obstrusive.
I think i18n most not depend on file format. Like Symfony, we just need parser (xml, ini, yml, po, whatever), each ext devs can choose what he like and use key path format like layout in J3.
$translator->trans('com.content.article');
<translation key="com_content_article" value="Article">
com: {
content: {
article: "Article"
}
}
COM_CONTENT_ARTICLE="Article"
maybe use Gettext ?
just _("Article")
instead of COM_CONTENT_ARTICLE
Article is just an example. We can have more complicated situations.
AFAIK
- Gettext use compiled file for translation and cache this on HTTP Server (Restart to clear).
- Don't think so easy to override language at runtime.
- We are directly on an extension without any ways to modify behaviors.
- Need ASCII key/reference.
Symfony use symfony/translation.
- ArrayLoader - to load catalogs from PHP arrays.
- CsvFileLoader - to load catalogs from CSV files.
- IniFileLoader - to load catalogs from ini files.
- MoFileLoader - to load catalogs from gettext files.
- PhpFileLoader - to load catalogs from PHP files.
- PoFileLoader - to load catalogs from gettext files.
- QtFileLoader - to load catalogs from QT XML files.
- XliffFileLoader - to load catalogs from Xliff files.
- JsonFileLoader - to load catalogs from JSON files.
- YamlFileLoader - to load catalogs from Yaml files (requires the Yaml component).
We need to search why not just gettext only.
Added some requirements to the intro.