cakephp - translating the Time text to another language -



cakephp - translating the Time text to another language -

how can translate default cake php time helper strings in application, i'm using in cake php function called timeagoinwords time helper function, give me text 5 hours, 52 minutes ago .

i want translate language, how can ? searched documentation , didn't .

<?php echo $this->time->timeagoinwords($question['question']['created']) ?>

you need customized helper stuff done. timeagoinwords helper not give flexiblity of replacing words words.

here, create file called timeagohelper.php under view/helper

i not sure language want translation in, write in english, can replace words.

<?php app::uses('apphelper', 'view/helper'); class timeagohelper extends apphelper { public function __construct(view $view, $settings = array()) { parent::__construct($view, $settings); } public function timeago($datetime) { $datetime1 = new datetime($datetime); $datetime2 = new datetime('now'); $obj = $datetime1->diff($datetime2); if($obj->days == 1) { $time = $obj->format('%a day'); // replace word } elseif($obj->days == 0) { if($obj->h == 0) { if($obj->i == 0) { $time = $obj->s . ' seconds'; // replace word } else { $time = $obj->i . ' minutes'; // replace word } } else { $time = $obj->h . ' hours'; // replace word } } else { $time = $obj->format('%a days'); // replace word } homecoming $time.' ago'; // replace word } }

load helper in action or controller.

i have been using php 5.5 since quite sometime, not sure if works on lesser versions, i.e. don't remember if concat allowed done seconds , minutes. incase, doesn't work, assign them variables , concat those.

use in view's .ctp file so:

$this->timeago->timeago($question['question']['created']);

ps: caketime comes in handy too, check out api possibilities.

cheers!

cakephp cakephp-2.0 translation

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -