Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8299409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:08:36+00:00 2026-06-08T16:08:36+00:00

I want to be able to test my cakephp web page using the localization

  • 0

I want to be able to test my cakephp web page using the localization features.

I use the translate function __() and I also use the date and time function: toLocaleString()

I wanted to know how can I test the translation and localization in a simple way.

I know that toLocaleString() will output the date and time in the local format.

I tried using the following code in my controller’s beforeFilter():

$this->Session->write('Config.langauge', 'ger');
Configure::write('Config.language', 'fre');

The above two lines of code didn’t work.
This did not work either:

setlocale(LC_ALL, 'de', 'ge');

I am using Ubuntu 10.04.
I also installed a spanish, french and german language pack.

In the cakephp debug toolkit, it shows that the language has changed, but the date and time string do not change at all.
I am not sure what I am doing wrong.

As for testing, the date and time should work once the locale is set, but for the translate functions, how do I test those?
I looked into the cakephp documentation, but it says to use the i18n console commang.
I tried running the command to extract pot files and I chose my source and output directory, but nothing showed up in the directory when it was done.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T16:08:38+00:00Added an answer on June 8, 2026 at 4:08 pm

    See the below url

    http://book.cakephp.org/2.0/en/core-libraries/internationalization-and-localization.html

    Or try this:

    //Internationalizing Your Application
    
    <h2><?php echo __('Posts'); ?></h2>
    
    The default domain is ‘default’, therefore your locale folder would look something like this:
    
    /app/Locale/eng/LC_MESSAGES/default.po (English)
    /app/Locale/fre/LC_MESSAGES/default.po (French)
    /app/Locale/por/LC_MESSAGES/default.po (Portuguese)
    
    
    <?php
    // App Controller Code.
    public function beforeFilter() {
        $locale = Configure::read('Config.language');
        if ($locale && file_exists(VIEWS . $locale . DS . $this->viewPath)) {
            // e.g. use /app/View/fre/Pages/tos.ctp instead of /app/View/Pages/tos.ctp
            $this->viewPath = $locale . DS . $this->viewPath;
        }
    }
    
    
    or:
    
    
    <?php
    // View code
    echo $this->element(Configure::read('Config.language') . '/tos');
    
    
    
    
    //Localization in CakePHP
    
    <?php
    Configure::write('Config.language', 'fre');
    ?>
    
    <?php
    $this->Session->write('Config.language', 'fre');
    ?>
    
    
    <?php
    class AppController extends Controller {
        public function beforeFilter() {
            Configure::write('Config.language', $this->Session->read('Config.language'));
        }
    }
    ?>
    
    
    ///Translating model validation errors
    
    <?php
    class User extends AppModel {
    
        public $validationDomain = 'validation';
    
        public $validate = array(
            'username' => array(
                    'length' => array(
                    'rule' => array('between', 2, 10),
                    'message' => 'Username should be between %d and %d characters'
                )
            )
        )
    }
    ?>
    
    //Which will do the following internal call:
    
    <?php
    __d('validation', 'Username should be between %d and %d characters', array(2, 10));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Nunit, I want to be able to write a test fixture that will
Quite simply I want to be able to test that a Asp.Net web forms
I want to be able to execute Behat based test scenarios within Jenkins. Behat
I want to be able to split a big test to smaller tests so
To test an app I'm building, I want to be able to emulate the
I'm using LaTeX and BibTeX for an article, and I want to able to
I want my Food class to be able to test whenever it is equal
I want to be able to test if theForm is defined, meaning it found
If I want to be able to test my application against a empty MySQL
I want to be able to test some inner functions that I have without

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.