I am following this doc to learn localization basic. I have followed below step
I have an index.ctp file here I have added a headline
<h2><?= __('Popular Articles') ?></h2>
Now for .pot file I have used below command
bin/cake i18n extract
default.pot file generate well then I have moved this file to
src\Locale\jp\default.pot
Here I have found below line in default.pot
#: Template/Tests/index.ctp:1
msgid "Popular Articles"
msgstr ""
I have added msgstr "人気の記事"
Now in config/bootstrap.php I have added below code to make default language jp
ini_set('intl.default_locale', 'jp');
Still it's giving me same output.
change the file name as default.po
change the folder name as ja_JP
and also ini_set('intl.default_locale', 'ja_JP');
Translation folders can either be the two letter ISO code of the language or the full locale name such as fr_FR, es_AR, da_DK which contains both the language.
more info: http://book.cakephp.org/3.0/en/core-libraries/internationalization-and-localization.html#language-files
Related
I'm trying to localize my php app that uses .ctp files for the views.
Here a sample of a file's content:
<h2><?php __('Menu');?></h2>
<table >
<tr >
<td style="text-align:left>
<?php echo $html->link('Main Config','/admin/configs/index')?>
</td>
</tr>
PS: this is not my code and I cannot change it - but I need to translate it!
I tried following threads using POEdit and tried this solution, which however seems to be on a previous version of POEdit...
So I created a new po file for de-DE in my root directory (standard encoddings, ...), opened the catalog's preferences and added . and one specific /subdir/test.ctp file containing above code) to my source paths, then added _ and __ to the additional keywords (as well as some others I found to contain some text such as input and link, for example).
Then, whether I use update, update from source, no string is found - it says "Translated 0 from 0 (0%)"...
What am I doing wrong here?
NOTE: this is on a windows 10 pc with only POEdit installed, I didn't install php nor php-gettext installed directly on my machine, but they're supposed to be embedded in POEdit from what I could read...
.ctp extension is not recognized by GNU gettext's xgettext as a PHP extension — such files are skipped over. I just added special treatment for it to Poedit a week ago, so it will be fine in Poedit ≥ 2.0.8.
Until then, you can add a custom extractor (using the same syntax as in Poedit 1, see the placeholder examples in the window where you enter it) for *.ctp files.
I have cake 3 fresh installation.
I have a simple po file in this location src/Locale/de_DE/default.po with the following content.
msgid "test"
msgstr "test in german"
On my home page template file I have simple <?php echo __('test'); ?>
I need to set the locale on the fly, so I add this to my AppController's beforeFilter(or initialize) - I18n::locale('de_DE'); however test is not being translated. I can't figure out, what Im missing. I tried renaming all to iso2 - de, but it did not translate either.
Thanks
Open your Terminal, cd to your project folder (the one which contains the bin folder) and type:
bin/cake cache clear_all
That's all. Refresh your page right after.
One last thing, be sure to place your .po files in:
Locale/de_DE/your_translations.po
I like to use POEdit to manage my translations. Cheers.
Maybe this helps:
If you are working on a local maschine and use bin/cake i18nto generate the translation files, make sure the files are readable by your local webspace.
This drove me cracy.
Hi i am getting one problem in adobe dreamweaver CS3.
Currently dreamweaver not supporing to find any text from .ctp file in the entire project. I can see here it supports .php, .js, .html etc. So i am unable to search .ctp all files in entire project.
Ex-
Suppose i want to find $this->webroot in the entire project. When i search it says Done, Not found in 1366 documents. But i wrote this text in my default.ctp file
screenshot
How to search .ctp file. There is no any configuration for change the extension?
Thanks
For Configure/Opening CakePHP CTP Files in Dreamweaver 3 files that you need to edit:-
C:\Program Files\(Adobe or Macromedia)\(Adobe )Dreamweaver(version like 8 or cs3)\configuration
Open up “Extensions.txt” and on the first line at the very end add THTML and CTP separated by commas, so the line should read:
,MASTER,THTML,CTP:All Documents
Similarly add these two extensions to the “:PHP Files” line.
PHP,PHP3,PHP4,PHP5,TPL,THTML,CTP:PHP Files
Next open the “DocumentTypes” folder and edit the “MMDocumentTypes.xml” file, just open it up using notepad or wordpad. Search for the line which has an id “PHP_MySQL” and add the THTML/CTP file extensions to both the “winfileextension” and “macfileextension” so the line should read:
winfileextension=“php,php3,php4,php5,thtml,ctp”
macfileextension=“php,php3,php4,php5,thtml,ctp”
The final file is another version of the “Extensions.txt” which is located in your “Documents and Settings” Folder in my case this is “C:\Documents and Settings(User_Name)\Application Data(Adobe or Macromedia)(Adobe )Dreamweaver(version like 8 or cs3)\configuration” just add the very same things you inserted earlier in “Extensions.txt” .
In my CakePHP application,
By using cake.bat i created POT files and by using PoEdit I created PO files.
So by writing __('myword') i can see localized word in my application successfully.
But now I need to localize "timeAgoInWords".
When i run cake i18n extract, script didn't get the _dn() words in CakeTime
http://api20.cakephp.org/view_source/cake-time#line-522
So i created a dummy.ctp file and copy-pasted contents from cake-time file to dummy file.
I run cake script and POEdit again. And it created instances like below, into the file app/Locale/tur/LC_MESSAGES/default.po
#: View\App\dummy.ctp:30;33
msgid "%d minute"
msgid_plural "%d minutes"
msgstr[0] "%d dakika"
msgstr[1] "%d dakika"
In core.php i already set default language to Turkish:
Configure::write('Config.language', 'tur');
But when i check my application, results of timeAgoInWords came in English.
How can i fix this
Cake's messages are extracted into a different domain, in this case, the cake domain. This means that cake messages will not be extracted into your default.pot file, but will go into cake.pot file.
Curiously, cake.pot doesn't seem to be included in the download, nor does the i18n shell allow you to pass a param to include the cake core during extraction. However, it is still easily done (my comments start with a #):
$:/var/www/path/app$ cake i18n extract
# if will ask you here if you want to extract from your app folder
# simply press enter to confirm
What is the path you would like to extract?
[Q]uit [D]one
[/var/www/path/app/]
# now it will ask you again, in this case enter the cake path
What is the path you would like to extract?
[Q]uit [D]one
[D] > /var/www/path/lib/Cake
# third time, just press enter
What is the path you would like to extract?
[Q]uit [D]one
[D] >
# press enter to accept the app/Locale
What is the path you would like to output?
[Q]uit
[/var/www/path/app//Locale] >
# press enter to keep translation domains deparate
Would you like to merge all domains strings into the default.pot file? (y/n)
[n] >
Now wait for the extraction to finish and enjoy the pain of translating ;)
I use cakePHP 2.0 and use the console tool to create one .../app/locale/default.pot . Now, I would like to get my site translated into multiple languages. I read the paragraph about internationalization in the cakephp cook book (http://book.cakephp.org/1.2/en/view/162/Internationalizing-Your-Application).
I copy the default.pot files into
.../app/locale/eng/LC_MESSAGES/default.pot
.../app/locale/fre/LC_MESSAGES/default.pot
.../app/locale/pol/LC_MESSAGES/default.pot
...
And enter the tranalations string with an utf-8 text editor (as gedit). And ... my site do not get translated at all.
I have noticed the AppController may implement some code to change the Configure::write('Config.language', some_three_letters_language), as the configuration changed nothing, I have implemented some very simple code.
// in AppController
public function beforeFilter() {
Configure::write('Config.language', 'fre');
}
Why does the translation function always return it arguments and not the translated string in .pot files ( in views, __('Something') -answers-> 'Something')?
I found nowhere were .pot files are translated into .po. How can I get those .po files, with REHL or CentOS (cannot get any suitable packet with po or poeditor in the name)?
Thanks for your answer.
.pot and .po files are the same file format. .pot stands for "PO template". The difference being that you're supposed to use this template file and give it to your translators, who will produce the translated .po files. The .pot file is the template for several localized .po files. See http://www.gnu.org/software/gettext/manual/gettext.html#Files.
In other words, just renaming .pot to .po will do.
In the proper gettext workflow, there's the msginit tool for doing this, which will also set a number of headers to the correct values for the chosen locale.