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
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'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.
0
Comments
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.
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); }
But we have other applications (vanilla, conversations) and plugins... so... maybe you still have write something : )
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.
Thanks a lot!
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);
function
Plural
you should make locale dependent (likeFormatPossessive()
), 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"
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.
@S - I didn't realize that. Thanks for the tip. I'll move that function over to the locale as well.
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!
you can test my vanilla: http://www.tribbun.com/eskiacik/
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.