Locale & translations
  • SponeSpone
    Posts: 20
    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.
  • 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(http://www.poedit.net/), which list all the translatable strings.
  • SS
    Posts: 453
    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\class.gdn.php)

    public static function Translate($Code, $Default = '') {
    if ($Default == '')
    $Default = $Code;
    InterceptLangCode($Code); // <-- hack
    return Gdn::Locale()->Translate($Code, $Default);
    }
  • SS
    Posts: 453
    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.
  • SponeSpone
    Posts: 20
    Thanks @mayank & @S =)
  • MarkMark
    Posts: 4,880
    @S - this is awesome, I was going to write something like this myself - now I don't have to :)
  • SS
    Posts: 453
    @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
    Posts: 4,880
    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
    Posts: 453
    @Mark
    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
    Posts: 4,880
    @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 - http://github.com/lussumo/VanillaAddons
  • KirillKirill
    Posts: 11
    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!
  • KirillKirill
    Posts: 11
    I tried to use Mark's VanillaAddons, but it give's me a lot of fatal errors
  • CloughClough
    Posts: 17
    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
    Posts: 453
    @Mark
    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);
    English:
    1 comment
    2 comments
    3 comments
    ...
    5 comments
    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"<br />
    I suggest new plural translate method by function (example for some eastern-european language look here http://pastebin.com/d4d5e3595

    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
    Posts: 4,880
    @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.
  • SilencerSilencer
    Posts: 16
    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
    Posts: 17
    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: http://www.tribbun.com/eskiacik/
  • SilencerSilencer
    Posts: 16
    @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
    Posts: 4,880
    @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.
  • [-Stash-][-Stash-]
    Posts: 2,610
    @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
    Posts: 4,880
    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.
  • SilencerSilencer
    Posts: 16
    @Mark
    Thanx for your quick reply. Recently you fixed a translation issue on github (http://github.com/lussumo/Garden/commit/3ca8325497d01776891adefe490db954482ed926). But where can I translate this? I didn't find the phrase in applications/garden/locale/en-CA/definitions.php.
    For people wondering what a pull request is: http://github.com/guides/pull-requests .
  • MarkMark
    Posts: 4,880
    @Silencer - In order to translate it, you just take the string that was passed into the Gdn::Translate() function and assign accordingly. If you just want to make a few changes here and there, you can use the conf/locale.php file to make the changes. If you want to make an entirely new translation locale, make the appropriate folder within the locale folder and add a "definitions.php" file within. You'll need to assign that locale after you've created it. You do that through the conf/config.php file with the Garden.Locale setting.

    Your translations appear in either of those places like this:
    <?php if (!defined('APPLICATION')) exit();
    $Definition['Apply for Membership'] = "Register Now!";
    $Definition['Sign In'] = 'Login';
  • SilencerSilencer
    Posts: 16
    @Mark
    Thank you so much! A few more questions:
    1. What is better for php: 'Login' or "Login"?
    2. There are different locale folders with "definitions.php". In "conversations" it has one value ($Definition['RecipientUserID'] = 'recipient';), in "skeleton" no value and in "vanilla" no value as well (the copyright is missing here). Most values are in the "/applications/garden/locale/en-CA/definitions.php". Can I put everything here, so I just have to take care of one "definitions.php" or do I have to make multiple files in the corresponding folders?
    3. I found a bug (login screen is empty after wrong password) when entering german umlauts here:
    $Definition['ErrorCredentials'] = "z.B. ü";
    Edit: The umlaut issue was caused by the wrong file encoding. Important: it has to be UTF-8 without BOM! If you use the notepad++ editor (which is very good btw), you can open the file and go to "encoding" => "convert to UTF-8 without BOM".

    It would be great if we could make a single "definitions.php" with all necessary values for translation as a template. This could people put in their "/applications/garden/locale/new-language/" folder after translation.

    @Clough
    It would be great if you could post your "definitions.php" and we search and post the rest of the missing values from the Gdn::Translate() functions throughout the software.
  • aminimaaminima
    Posts: 7
    OH MY GOD! Why it is too hard to translate Vanilla 2?!!! Vanilla 1 had a definitions file and we could easily translate it to our language.
    I installed Mark's addon but I got fatal error about database table. I did as S said but again an error about syntaxes...
    could you write a simple structure about translating Vanilla 2 ???
  • lucluc
    Posts: 983
    v2 is not out yet.
    It will be easier to translate once it's out, but the translation part is not the focus of the developpers right now, it will be later when it's closer to release.

    I'm pretty sure Mark and the other devs will make something nice to work with in order to translate v2/garden.
  • ralevralev
    Posts: 1
    I'll probably not install this forum only because of all the headache around the translation...
    It's a pity, because it looks like a nice forum platform.
    A PO file would be very handy.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter

In this Discussion

Who's Online 5

AltazarIdanpulkitsahotataranxvik