Top 10 project localization tips

Tram Ho

Hi everybody.

One of the programming problems that you will inevitably encounter is the localization of applications in different countries of linguistic data.

Today I will introduce you 10 tips to solve the language problem.

1. Set timezone for the application

The application should set a time zone for itself. Otherwise, the server / server time zone will be lost, which is probably not what the user wants.

You should run this function as soon as possible in your project.

Alternatively, you can use the timezone_identifiers_list() function to create a list of time zones from which the user can choose.

For example:

The above function will return a list of timezone like this:

  • [Africa / Abidjan] => Africa / Abidjan [+0: 00]
  • [Africa / Accra] => Africa / Accra [+0: 00]
  • [Africa / Addis_Ababa] => Africa / Addis_Ababa [+3: 00]
  • [Africa / Algiers] => Africa / Algiers [+1: 00]
  • [Africa / Asmara] => Africa / Asmara [+3: 00]
  • [Africa / Bamako] => Africa / Bamako [+0: 00]
  • [Africa / Bangui] => Africa / Bangui [+1: 00]
  • [Africa / Banjul] => Africa / Banjul [+0: 00]
  • [Africa / Bissau] => Africa / Bissau [+0: 00]
  • ….

You can then use select to let users choose their timezone.

2. Set the timezone for mysql from the project

Projects are usually hosted on servers in different time zones, compared to developers and users’ local machines. Therefore, mysql’s time zone needs to be set to the user’s time.

You can execute the following SQL statement to set timezone for MySql:

The date function of php with the parameter P used to get the time difference between the current and the UTC time.


For the TIMESTAMP fields in mysql, every time-date combination will be converted to the correct timestamp by mysql , since mysql itself is in the correct time zone.


When using datetime columns, the application needs to convert date and time values ​​into UTC, then save to mysql.

When retrieving data from a database, we must convert that value into the application’s time zone.

Save to database:

3. Set collation for database at creation time

collation database collation needs to be set right from the start, to avoid errors later and always be consistent when backing up and dumping the database.

Or you can edit the collation after creating the database. Setting collation , character set from the beginning for the database ensures that all subsequent tables and columns will be the same by default.

4. Set the character for mysql connection object

When the application is displaying non-English characters, it must set the character encoding of mysql connection.

For example:

It’s easy, isn’t it? ?

5. Set the correct character for htmlentities

The htmlentities function is used to print out the content, previously provided by the user. Prior to php 5.4, the default character encoding used as ISO-8859-1 could not display languages ​​like hindi, bengali, russian etc.

Php 5.4 onwards, the default encoding will be UTF-8 which will solve most problems, but still be more aware of it if your application is multilingual.

You can also use the mb_list_encodings function that can be used to create lists for selected users or you will depend on the user’s language and processing.

After running the above function, you will get the following result:

  • [UTF-32BE] => UTF-32BE
  • [UTF-32LE] => UTF-32LE
  • [UTF-16] => UTF-16
  • [UTF-16BE] => UTF-16BE
  • [UTF-16LE] => UTF-16LE
  • [UTF-8] => UTF-8
  • [UTF-7] => UTF-7
  • [UTF7-IMAP] => UTF7-IMAP
  • [ASCII] => ASCII
  • [EUC-JP] => EUC-JP
  • [SJIS] => SJIS

6. Set encoding for non-html content by sending the correct headers

When you want to use the file: css, javascript, xml, etc., set the correct encoding via the header function like this:



7. Set character Sets b correctly for html and xml output

HTML: This is in the head tag of the html document

Support for html5:

XML: The first line of the xml document has the specified encoding

8. Set the correct locale

Setting the correct locale will be useful for language-related settings such as numeric formatting, currency symbols, etc. Setting the correct locale for the application should be set up as soon as possible in the project.

You should also provide the user with a list of locations to choose from, or from your language choose a locale to use appropriately.

9. Format numbers according to locale

When displaying numbers as regular numbers or amounts, you should format them with commas, decimals, etc. using the money_format function.

For example:

10. Date display format

The date format displays according to the user format.

There are several types of different commonly used date formats:

Dates must be formatted both when displayed and when being entered into an input form.

Format dates with strftime function:

Format with DateTime class:

Depending on the project, users should have the option to select the format to display the date and enter the date in the form or the programmer can choose the format according to the user’s locale to handle.


So I’ve finished 10 tips to localize the project, hoping to help you with any part of the programming process.

See you in the following article.

Thanks you!


Share the news now

Source : Viblo