Time_Ago_In_Words and Localize

Localizing timeAgoInWords in CakePHP

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 ;)

time_ago_in_words and localize

If you are using Rails > 2.2, the helper is already locale-aware.

Just download the right localization file from the locale repository and store it into your /config/locales path. Then set your locale preferences.

CakePHP 2.4 and Timehelper's timeAgoInWords locale

Normally I change current language like this:

$this->Session->write('Config.language', $lang);

I set default language like this in every request in core.php:

Configure::write('Config.language', 'tur');

Regarding to CakePHP documents I must add this code to my AppController:

class AppController extends Controller {
public function beforeFilter() {
if ($this->Session->check('Config.language')) {
Configure::write('Config.language', $this->Session->read('Config.language'));
}
}
}

After adding the code above to beforeFilter() of AppController, I refreshed /tmp/cache/persistent/ folder and everything works fine.

Edit:
This solution worked well for english but it didn't work for other languages.

Why ? As noted in this question cake looks for cake.po files inside your Locale folder.

For example if you want to see cake's messages in french, so you need to create this file:

/app/Locale/fra/LC_MESSAGES/cake.po

Where do CakePHP use cake.po records ?
For example: this method


You can create default po files like this: i18n shell tutorial

After shell's file creation, you can edit cake.po file for your language.


For some languages cake.po files are ready. For example: french file

You can find rest from there: https://github.com/cakephp/localized

CakePHP 2.4 and Timehelper's timeAgoInWords locale

Normally I change current language like this:

$this->Session->write('Config.language', $lang);

I set default language like this in every request in core.php:

Configure::write('Config.language', 'tur');

Regarding to CakePHP documents I must add this code to my AppController:

class AppController extends Controller {
public function beforeFilter() {
if ($this->Session->check('Config.language')) {
Configure::write('Config.language', $this->Session->read('Config.language'));
}
}
}

After adding the code above to beforeFilter() of AppController, I refreshed /tmp/cache/persistent/ folder and everything works fine.

Edit:
This solution worked well for english but it didn't work for other languages.

Why ? As noted in this question cake looks for cake.po files inside your Locale folder.

For example if you want to see cake's messages in french, so you need to create this file:

/app/Locale/fra/LC_MESSAGES/cake.po

Where do CakePHP use cake.po records ?
For example: this method


You can create default po files like this: i18n shell tutorial

After shell's file creation, you can edit cake.po file for your language.


For some languages cake.po files are ready. For example: french file

You can find rest from there: https://github.com/cakephp/localized

Cakephp understanding Localization..?

All this code will do is edit the $this->viewPath variable.

This will make CakePHP look in a different directory from the standard when calling render(). This is normally done if you intend to create different folders, each of which contains the View files for a specific localisation.

If your View folder currently looks like this:

View
- Elements
- Emails
- Errors
- Helper
- ...

It should, instead, look like this:

View
- deu
- Elements
- Emails
- Errors
- Helper
- ...
- Elements
- Emails
- Errors
- Helper
- ...

In this way, you can specify entirely different View files for lots of different localisations. The folders in the root directory should be the default localisation.

The reason it currently isn't doing anything is because it can't find the relevant view files when it makes the file_exists() check. Once you have restructured as necessary it should work fine.

How to translate words from $this- Time- timeAgoInWords?

Yes, they are in a different domain, the cake domain, the months are in that domain too. Take a look at the source, all translatable core messages are in that domain.

I'd suggest that you extract them using the I18N shell (backup your existing translations first in case you accidently overwrite them), it won't get simpler than that.

See Cookbook Console & Shells > I18N Shell > Generating POT Files



Related Topics



Leave a reply



Submit