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

klipklip New
edited August 2010 in Vanilla 2.0 - 2.8
So, I finally had some time to do some research how locale system of Vanilla works...
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 one
- 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
So it is not much.

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


Comments

  • MarkMark Vanilla Staff
    We are very open to getting help on the localization. I know @Todd has some ideas for how to make localization easier, as well. Hopefully he'll chime in.
  • sure, if there are some other thoughts I would like to create the best solution for everyone. Just let me know.
  • ToddTodd Vanilla Staff
    @klip, all of your suggestions look great to me and your thoughts about getting better support like this into the core would be awesome. Probably the ability to collect all required translations will remain in a plugin since it is more useful for translators rather than all forum admins. I'd also prefer keeping the locales in the conf folder.

    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.
  • @Todd, good to read that :) I'll try to do something.
    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.
    When talking about locale files loading I was talking about priority of loading, not priority of definitions used :)

    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:
    Process of reading definitions from locale files will take more time than just PHP include. It should be cached.
    Cache will be per language priority combination, not user. There can be thousands of users, but there is only limited number of language priority settings
    Cache has to be cleared when there is a change in any of the locale files.
  • ToddTodd Vanilla Staff
    Okay, I think we're on the same page here.

    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?
  • @Todd yes, I do already: http://github.com/tomasklapka
    I'll pull the copy and try to code something then :)
  • ToddTodd Vanilla Staff
    What you want to do is fork and then pull the code from your own repository where you can push back. We'll then accept pull requests after review of course.

    Not sure if you knew this, but just want to make sure.
  • I have some svn experience, and I've tried git locally already, so it won't be problem I guess ;)
  • JFI: I'm having several busy weeks in work so this project is not dead. I just don't have free time to work on it at the moment :(
  • ToddTodd Vanilla Staff
    @klip. Have you done any work with localization? I am going to be doing some work on this so that language packs can be standardized, but I don't want to step on anything you've done.
  • edited November 2010
    according Gdn_Locale::Set of library/core/class.locale.php.
    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.

Sign In or Register to comment.