A simple trick to get the localized version of a model field is to add this little method to your models.
A simple trick to get the localized version of a model field is to add this little method to your models.
This guide is for more or less advanced users. If you just started with Yii or didn't worked with any web-framework before, you may should come back later :-)
The sql 'set time_zone' ensures that all dates retrieved are in UTC time. If your MySql server has the time zone names installed then use 'UTC' instead of '+00:00'.
Copy the code at the end of this wiki for LocalTime.php and DefaultDateTimeParser.php int...
In case of a multilingual application, one might consider it a reasonable approach to store the preferred language of the user in a session variable, and after that, every time a page is requested, to check this session variable and render the page in the indicated language.
This tutorial shows a Yii-way of doing this.
We implement an event handler for the onBeginRequest event; as the nam...
You have a multilingual application, and you want the URL of a page to be different for different languages, to account for SEO. The URL for the contact page for example should look like http://something.com/en/contact in english, and http://something.com/de/contact in german. This tutorial describes how to make it happen.
Note that currently selected language is always a part...
The giix code generator has out of the box i18n support for model names and attribute labels (besides other cool features > check it out!) .
But I want to factor in not only the plural form, but also the grammatical cases (especially the accusative) while translating 'Manage Objects', 'Create Object', 'Edit Object' etc.
As you know, the CDetailView widget displays details of a single model. If no formatting is specified, boolean values that are stored in the database as 0 and 1, are represented in the detail view as 0 and 1. If formatted as boolean, they are represented as 'No' and 'Yes'. We want to add i18n support, so that Yes and No appear in the current language.
There are scenarios when you work with DVCS (like [Mercurial]( http://mercurial.selenic.com/) or [Git]( http://git-scm.com/)) and CDbMessageSource. To my experience keeping the development database and production database in sync can be very...
Yii core messages refer to static text strings in the core Yii framework code which are meant to be displayed to end-users (e.g. core exception messages, default validation error messages). Customization of these core messages is needed in two circumstances:
As seen in this post, Yii doesn't enforce how language is set and maintained within the session.
By default, the decimal separator in php (also in mysql) is a dot (.). So when we work with floats in Yii (in calculations, validation, sql statements etc.), the decimal separator has to be a dot. If we want to use for example a comma (,) as the decimal separator, that is if we want to display numbers and enable users to enter numbers with a comma before the decimals, we have to...
I needed all messages with their translation into javascript. This is my solution:
So here is my complete solution - note that I'm using the 'short' date format throughout.
To fix issues with display of special language characters once and for all there's a solution: use Unicode UTF-8 everywhere. If everything is set up to use Unicode, you can use mostly every language in your application.
Language translation is a common requirement in multi lingual sites. In Yii, we can translate using message and view translation.
This topic is related with langhandler extension
Efficient coding with Yii implies efficient use of the code generator. This article shares the personalised Gii templates that were built starting from the standard templates proposed by AweGen.
You would find having such a need in most Yii Projects. Your database needs a specific format to store date fields, while you may want to display it in different formats to the users on forms and other views.
Example settings when using Gettext for i18n.