FormHelper of CakePHP 2.0.6 (in 1.3 works perfectly), not accept app/Locale/pt_br/LC_MESSAGES/default.po.
When I open file for check, I see this:
__d('cake', 'January');
How I can override "__d" and/or 'cake' plugin.
Because, when I change _d() to _(), works fine, but I think this not a perfect solution.
__('January');
Thanks.
Sorry for my english, I'm Brazilian
I searched for like an hour for a solution because I'm having the same problem. Here is how I did it:
Create cake.po translation file in /app/Locale/[your language key]/LC_MESSAGES/
Copy the following in this file and translate the msgstr entries to your language:
msgid "January"
msgstr "Januar"
msgid "February"
msgstr "Februar"
msgid "March"
msgstr "März"
msgid "April"
msgstr "April"
msgid "May"
msgstr "Mai"
msgid "June"
msgstr "Juni"
msgid "July"
msgstr "Juli"
msgid "August"
msgstr "August"
msgid "September"
msgstr "September"
msgid "October"
msgstr "Oktober"
msgid "November"
msgstr "November"
msgid "December"
msgstr "Dezember"
Add Configure::write('Config.language', '[your language key (same as the folder created above)]'); to your bootstrap or set it elsewhere.
Tada!
Explanation: The month names in the CakePHP helper are translated via the cake domain: __d('cake', 'January') (see file on github) so normal translation in the default.po file won't work.
Move all those translations into app/Locale/pt_br/LC_MESSAGES/cake.po. The d in __d switches to another domain, and those domains are simply different files in the LC_MESSAGES directory.
Related
I need to get my php code multilingual. The translations are POEdit.com exports.
Because I want to display single and plurals I have to use gettext (the php array export of POEditor does not support plurals).
My problem:
Gettext does always return the input string (msgid), not the translated text.
My setup:
Windows 7 64-Bit german system locale
EasyPHP Devserver
Apache 2.4.18
PHP 5.6.17 + gettext enabled
Folders and Files:
web root = C:\Users\SM\PhpstormProjects\website
locales = C:\Users\SM\PhpstormProjects\website\src\i18n
polish translation = C:\Users\SM\PhpstormProjects\website\src\i18n\plk\LC_MESSAGES\messages.mo
PHP Code:
define('_LOCALES_DIR', 'C:\Users\SM\PhpstormProjects\website\src\i18n');
$locale = "plk";
$domain = "messages";
$rv['putenv'] = putenv("LC_ALL=" . $locale);
$rv['setlocale'] = setlocale(LC_ALL, $locale);
$rv['bindtextdomain'] = bindtextdomain($domain, _LOCALES_DIR);
$rv['bind_textdomain_codeset'] = bind_textdomain_codeset($domain,"UTF-8");
$rv['textdomain'] = textdomain($domain);
print_r($rv);
echo "pl: " . gettext("Benutzername");
PHP Output:
Array (
[putenv] => 1
[setlocale] => Polish_Poland.1250
[bindtextdomain] => C:\Users\SM\PhpstormProjects\website\src\i18n
[bind_textdomain_codeset] => UTF-8
[textdomain] => messages
)
pl: Benutzername
Expected output: "pl: użytkownik"
The .po file looks like this:
msgid ""
msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: POEditor.com\n"
"Project-Id-Version: website\n"
"Language: pl\n"
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
#:
msgctxt "Usermanagement"
msgid "E-Mail"
msgstr "e-mail"
#:
msgctxt "Usermanagement"
msgid "Passwort"
msgstr "hasło"
#:
msgctxt "Usermanagement"
msgid "Benutzername"
msgstr "użytkownik"
What I tried:
The return value of the setlocale("plk") ist "Polish_Poland.1250" so I tried to rename the "i18n/plk" folder to "i18n/Polish_Poland.1250" without luck.
use Polish_Poland.1250 as input language
Polish is only an example, tried it with different languages
added ".UTF8" and ".UTF-8" to the locale
tried php-gettext
checked the installed locales with the help of this script: https://stackoverflow.com/a/23286243
But always the same result :(
Does one of you have any ideas what am I doing wrong or could trie to get it to work?
UPDATE 2016-07-15 12:45:
One of my mistakes is the missing context, I had to use gettext() like this gettext("Usermanagement\004Benutzername");. Now it loads text from the mo files, but the wrong one. It always loads the mo file located in the "i18n/de_DE" folder. (Remember de_DE is the default language of my Windows installation). Even setlocale returns the entered locale (setlocales way to tell he successfully changed the locale), always de_DE is used. :/
I also tried additionally to set these to environment variables without any luck:
$rv['putenv=LANG'] = putenv('LANG='.$locale);
$rv['putenv=LANGUAGE'] = putenv('LANGUAGE='.$locale);
I'm trying to add translations to my webpage.
Unfortunately my translation isn't being read.
However, one translation is read (even though I ask for a different one).
My php code looks like this:
$language = "en_US"; //Hardcoded for debugging purposes
define("FOLDER_SPECIFICATION", "./locale/");
define("DOMAIN", "messages");
define("CODE_SET", "UTF-8");
putenv("LANG=" . $language);
setlocale(LC_ALL, $language);
bindtextdomain(DOMAIN, FOLDER_SPECIFICATION);
bind_textdomain_codeset(DOMAIN, CODE_SET);
textdomain(DOMAIN);
My folder structure looks like this:
root >
locale >
en_US >
LC_MESSAGES >
messages.mo
messages.po
nl_NL >
LC_MESSAGES >
messages.mo
messages.po
If I change the $language variable to en_US or nl_NL it still grabs the translation from nl_NL, if I remove the nl_NL folder it doesnt translate at all, this together means one thing: The en_US translation isn't being read.
Both messages.po contain headers and such and both are valid (I loaded them in poedit).
My question is: Why does it grab nl_NL even though I never told the code to grab it, and why isn't the other translation (en_US) being read?
Both .po files look like this (the 'Language' tag in the headers are obviously different):
msgid ""
msgstr ""
"Project-Id-Version: My Project\n"
"POT-Creation-Date: 2014-08-05 13:32+0100\n"
"PO-Revision-Date: 2016-04-19 10:43+0200\n"
"Last-Translator: \n"
"Language-Team: someone <s.omeone#something.com> \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.8.7\n"
"X-Poedit-Basepath: .\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"Language: nl_UL\n"
"X-Poedit-SourceCharset: UTF-8\n"
msgid "Banaan"
msgstr "Banana"
msgid "Appel"
msgstr "Apple"
How to disable adding references to *.po file? in POedit?
poedit adds references, but do not need it.
Example of my gettext file:
#: ../../../tests/cases/Command/SysInfoTest.php:49
#: ../../../tests/cases/Command/SysInfoTest.php:238
#: ../../../tests/cases/Command/SysInfoTest.php:248
msgid "ERROR__SYSINFO__INVALID_SAVE_PATH"
msgstr "The source type for the request is invalid."
and here is how I would like to:
msgid "ERROR__SYSINFO__INVALID_SAVE_PATH"
msgstr "The source type for the request is invalid."
is there any solutions? or do I need to parse and delete references manually?
The GNU gettext manual documents the --no-location flag for xgettext that does exactly what you want.
Is it possible to retrieve the msgid from a given msgstr without messing around with the po-files?
Reverse lookup? Not with the native PHP gettext extension. But you can use gettext.php from upgradephp. Specifically look for gettext___load_mo($fn,"domain"). It fills up a global $_GETTEXT array from the raw .mo data, and you could use array_flip($_GETTEXT["domain"]) to receive a msgstr->msgid mapping.
I am working on web application (used PHP, javascript language) , I have provided localization support to my application. Currently supported English language.
I am supporting another languages.
I know basic format of .po file i.e. :
msgid "Unknown login error"
msgstr “Please enter corrent credientioals"
I wanted to know standard format for writing po file.
Please suggest me, from where I will get po file standard format through with I can build good po file
http://www.gnu.org/software/hello/manual/gettext/PO-Files.html
Those are the most used tags:
#: = source file.
msgid = original string.
msgstr = denotes the string which to become the translation.
Example:
#: Folder/File.extension
msgid "Original String"
msgstr ""
Documentation