Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Vanilla Localization project
klip
New
So, I finally had some time to do some research how locale system of Vanilla works...
Here are my notes:
In Vanilla 1 there were add-ons allowing select language per user and I made an add-on to read language definitions from several places, and it was possible to setup language priorities per user, so if there was content available in more languages, the preferred language was used. http://www.vanillaforums.org/addon/341/extension-language-loader
Since localization is not a priority and current system is IMVHO kind of messy. I would like to offer some help with locale system. I have similar requests for the system as I made in the add-on for V1, so the requests are:
- locale setting configurable per user (and it means cache-able per user somehow)
- option to configure locale priorities, so the available definitions are displayed by user's priority
- maybe add another location of definitions: /locale/LANG/ (/conf/locale-LANG.php is not consistent with the rest of locale files policy)
If I am going to work on this, it would be better to change /library/core/class.locale.php so it supports these requests.
So I would like to know, @Mark and @Tim, if such functionality is something you would likely adopt in official source files?
If not, I would have to maintain this as patch, or make an addon doing this, but then again, there are no hooks to implement all these functionality, so the question is if you would like to add them?
Otherwise such add-on would need patching this file too.
Additionally I would like to add (this would not be necessary to be in the core, so maybe add-ons):
- option to display language code tag for content which is not in the most preferred language
- some clean way to collect all the definitions of all locale files quickly
- UI to help translators to create and edit localizations
Here are my notes:
$Configuration['Garden']['Locale'] = 'LANG'; changes locale globally for whole forum and there is no way to change it per user at the moment
locale definitions priority of loading:
/applications/APPLICATION_NAME/locale/LANG/definitions.php
/plugins/PLUGIN_NAME/locale/LANG/definitions.php
/themes/CURRENT_THEME_NAME/locale/LANG.php
/conf/locale-LANG.php or /conf/locale.php if not found
Gdn:GetAvailableLocaleSources() scans only /applications/dashbord/locale/*
There is no list of definitions and it is not easy to create oneSo it is not much.
- need to grab by addon when using forum or
- go through source files and get definitions from T()/Translate() function or
- use some other translation which already went through this definitions' collecting
In Vanilla 1 there were add-ons allowing select language per user and I made an add-on to read language definitions from several places, and it was possible to setup language priorities per user, so if there was content available in more languages, the preferred language was used. http://www.vanillaforums.org/addon/341/extension-language-loader
Since localization is not a priority and current system is IMVHO kind of messy. I would like to offer some help with locale system. I have similar requests for the system as I made in the add-on for V1, so the requests are:
- locale setting configurable per user (and it means cache-able per user somehow)
- option to configure locale priorities, so the available definitions are displayed by user's priority
- maybe add another location of definitions: /locale/LANG/ (/conf/locale-LANG.php is not consistent with the rest of locale files policy)
If I am going to work on this, it would be better to change /library/core/class.locale.php so it supports these requests.
So I would like to know, @Mark and @Tim, if such functionality is something you would likely adopt in official source files?
If not, I would have to maintain this as patch, or make an addon doing this, but then again, there are no hooks to implement all these functionality, so the question is if you would like to add them?
Otherwise such add-on would need patching this file too.
Additionally I would like to add (this would not be necessary to be in the core, so maybe add-ons):
- option to display language code tag for content which is not in the most preferred language
- some clean way to collect all the definitions of all locale files quickly
- UI to help translators to create and edit localizations
Tagged:
2
Comments
If you want to do some work on a branch in github I'd be happy to take pull requests and help debug stuff.
PS: Your priority listing of file locations seems to be in the opposite order. A conf/locale*.php is checked first, then the theme, etc.
I believe that files are loaded in the order: enabled apps, enabled plugins, current theme, /conf/locale-LANG.php and then /conf/locale.php
And it overwrites definitions. It means that the last occurance of the definition will be used.
Here are just some other thoughts:
That's a good point that the caching needs to be worked out to support multiple languages which should be no problem. We clear the locale cache in certain instances now, but we could probably also have a clear cache type button with locale settings to aid developers and edge cases.
Do you have a github username @klip?
I'll pull the copy and try to code something then
Not sure if you knew this, but just want to make sure.
this is the locale files load order(the next value overwride the pre one):
/applications/APPLICATION_NAME/locale/LANG.php
/applications/APPLICATION_NAME/locale/definitions.php
/plugins/locale/LANG.php
/plugins/locale/definitions.php
/themes/CURRENT_THEME_NAME/locale/LANG.php
/locales/CURRENT_LOCALE/*.php
/conf/locale-LANG.php
/conf/locale.php
as instance, if /locales/CURRENT_LOCALE/definitions.php contains:
$Definition['Security Check'] = 'Security Check A';
and /conf/locale.php contans:
$Definition['Security Check'] = 'Security Check B';
in the last , the page will display: 'Security Check B'.
and if want to take the new enabled locale effect, there is another place need to modify ,which is config-defaults.php:
$Configuration['Garden']['Locale'] = 'NEW_LOCALE';
as example:
$Configuration['EnabledLocales']['Zh_cn'] = 'Zh_cn';
now we can saw the new Locale.
BTW: is there a tool to extract all the T('some string need to translate') from the source code tree?
if yes, that should be very very helpful for translator.