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.

Locale & translations

edited September 2009 in Vanilla 2.0 - 2.8
Hello there!

I'm starting an early French (fr-FR) translation of Garden and Vanilla 2. I've understood that all the translations have to be in the proper application/plugin locale/ folder.

I need a list of all the strings I have to translate. Does such a list exist or do I need to create it myself by searching all the calls to Gdn::Translate() method?

Thanks in advance.


  • edited September 2009
    I think currently there is no such function that will list all the translatable strings. Correct me if I'm wrong.

    It would be nice if Garden provides the way to search all the translatable strings and create a defination.php file, which will have all the strings with blank translation.

    For now, I use PoEdit editor(, which list all the translatable strings.
  • SS ✭✭
    edited October 2009
    I need a list of all the strings I have to translate.
    We all need it, But it doesn't exists yet.

    I can suggest you a temporary solution of mine.
    1. Create file conf\bootstrap.before.php and add function
    function InterceptLangCode($Code){ //$Application = GetDumpDispatcherValue('_ApplicationFolder'); //if(True || $Application){ $Application = 'garden'; //$ControllerName = ''; //[_ControllerName:private] => plugin //[_ControllerMethod:private] => loadup $LocalePath = PATH_APPLICATIONS.'/'.$Application.'/locale/TR/'; if(!is_dir($LocalePath)) mkdir($LocalePath, 0777, True); if(!file_exists($LocalePath.'definitions.php')){ file_put_contents($LocalePath.'definitions.php', "<?php if (!defined('APPLICATION')) exit();\n\n"); } // PATH_ROOT include $LocalePath.'definitions.php'; if(Empty($Definition)) $Definition = array(); if(!array_key_exists($Code, $Definition)){ $Code = str_replace('\'', '\\\'', $Code); $S = "\$Definition['$Code'] = '$Code';\n"; $Trace = debug_backtrace(); $CountTrace = Count($Trace); for($i = 0; $i < $CountTrace; $i++){ $TraceInfo = $Trace[$i]; if($TraceInfo['function'] != 'Translate') continue; if(array_key_exists('file', $TraceInfo)){ $File = str_replace('\\', '/', str_replace(PATH_ROOT, '', $TraceInfo['file'])); $File = str_replace('.php', '', $File); $C = file_get_contents($LocalePath.'definitions.php'); //$FilePattern = preg_quote($File, '/'); if(!strpos($C, $File)) $S = "// $File\n$S"; //$S = "// $File\n$S"; break; } } file_put_contents($LocalePath.'definitions.php', $S, FILE_APPEND); } //} }

    function GetDumpDispatcherValue($Name){ $Dump = print_r($GLOBALS['Dispatcher'], True); if(preg_match('/\['.$Name.':private\] \=\> (\w+)/', $Dump, $Matches)) return $Matches[1]; }

    2. Modify function Gdn::translate (library\core\
    public static function Translate($Code, $Default = '') { if ($Default == '') $Default = $Code; InterceptLangCode($Code); // <-- hack return Gdn::Locale()->Translate($Code, $Default); }
  • SS ✭✭
    edited September 2009
    3. See file garden\locale\TR\definitions.php. In this file will be English lang code that passed to Gdn::Translate(). You will have most of language definitions (but not all). I've noticed that in some place double translate take place. I think such method is good start for localization for Beta.
  • MarkMark Vanilla Staff
    @S - this is awesome, I was going to write something like this myself - now I don't have to :)
  • SS ✭✭
    edited October 2009
    @Mark, This hack function puts all lang codes into applications/garden/locale/

    But we have other applications (vanilla, conversations) and plugins... so... maybe you still have write something : )
  • MarkMark Vanilla Staff
    I started working on the translation app for this site. It's going to be a part of the addons site, so it will be open sourced at github. I'm currently away, but I will be releasing it either later this week or next.
  • SS ✭✭
    edited November 2009
    I've noticed in last commits on GitHub that Locale class is Pluggable now,

    Make it pluggable only for one event "BeforeTranslate" I think it is bad idea. It was first of all.

    Secondly, Translate() function is most frequently used function in code. So, I believe that FireEvent there it is major hit for performance.

    Thirdly, in most cases we don't need to override Translate() or Locale class. If we really need modify it we can override entire class in bootstrap.before.php.
  • MarkMark Vanilla Staff
    @S - I just did it so that I can grab all of the translation codes as they run through it. You can see how I've used it in the addons repo -
  • Sorry, but I tried for 2 days to make a locale file and recieved only errors. Can anybody give me an example of non english locale for Vanilla 2? If it's possible, I'd like to see a list of the strings too...
    Thanks a lot!
  • I tried to use Mark's VanillaAddons, but it give's me a lot of fatal errors
  • CloughClough
    edited January 2010
    i have started translate my local language.. But some code was hard coded.

    in vanilla/settings/hooks.php

    Line 18:
    $Sender->Menu->AddLink(Gdn::Translate('Discussions'), 'Disscussion', $DiscussionsHome, FALSE);

    Line 40:
    $Sender->Menu->AddLink(Gdn::Translate('Discussions'), 'New Discussion', '/post/discussion', FALSE);
  • SS ✭✭
    function Plural you should make locale dependent (like FormatPossessive()), because there are languages which have more than one plural form of a word, and this form depends of number for this word.

    I give you example.
    Current translate method.
    echo sprintf(Plural($Discussion->CountComments, '%s comment', '%s comments'), $Discussion->CountComments);
    1 comment
    All grammar is correct.

    Some eastern-european language:
    1 komentár
    2 komentáre
    5 komentáre <-- gramma incorrect here, correct is "5 komentárov"

    I suggest new plural translate method by function (example for some eastern-european language look here

    For English PluralForm() function will look like:
    function PluralForm($N, $SingularCode){
    return ($N == 1) ? 1 : 0;

    So, maybe be add TranslatePlural method in Gdn_Locale or so.
  • MarkMark Vanilla Staff
    @Clough - Thanks for the tips. There are probably a handful of mistakes like that throughout the app. Please keep posting them if you find them so we can get them fixed.

    @S - I didn't realize that. Thanks for the tip. I'll move that function over to the locale as well.
  • Hi everyone,
    can we expect a single definitions.php for a complete translation or a system based on mo/po files (as in wordpress) in the future?
    What files do I have to translate now if I want a complete translation?
    Anyway, thanx Mark for sharing all this with us!
  • CloughClough
    edited March 2010
    100% translate is not possible now with definition.php. Because some data gettin sql data. You must edit sql data or before install to translate structure.php. İ have translated %70 with definition.php maybe later i can share my definition.php. Why may be due to waiting for changes of this ware.

    you can test my vanilla:
  • @Mark
    Could you please provide a guideline for translations and put translation consistency on your agendy. Right now it is extremely confusing and as a lot seems to be hardcoded translating is too much of an effort (and updating as well). This is sad, as your application in general is so awesome, but spreading in non-english speaking areas of the world is limited right now.
  • MarkMark Vanilla Staff
    @Silencer - it is on the agenda, but we're relying on the community quite a bit for help on this as it is definitely not at the top of our list right now. We really need people to implement fixes when they run across translation mistakes (strings being echo'd to the page instead of run through a translator, etc) and send us pull requests on GitHub.
  • StashStash
    edited April 2010
    @Mark, if that's the way you're planning on getting translations from the community, you aren't going to get as much as you could. Git(hub) is a significant barrier to entry. I've still not figured it out to do what you just wrote and there are plenty of less technical/more time precious people than me who could otherwise be contributing.
  • MarkMark Vanilla Staff
    edited March 2010
    Yes, you are right. We just don't have the resources to get even the documentation to the point where it clearly explains how to do things. We are hiring, but it's been a tough road finding people here in Montreal. There are some promising people right now, though. There is just too much work for Todd and I to do it alone. In the coming weeks things should start getting better as we add people to the team.
Sign In or Register to comment.