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.
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
Pluralyou 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"<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.
@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.
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 .
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';
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.
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 ???
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.
It's a pity, because it looks like a nice forum platform.
A PO file would be very handy.
http://vanillaforums.org/addon/localedeveloper-plugin
http://www.vanillaforums.org/addon/browse/locales/recent/2
http://www.vanillaforums.org/page/Localization
Is it really that bad?