We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to make the user manually select english/japanese language for an existing project.

Hi guys, I have developed a small project using phalcon, in which the default language is japanese, but now the requirement is like a user should manually select either english or japanese language by clicking any of these two links from the homepage. Is there any way to implement this, I am a newbie in phalcon. can anyone please help me step by step how to do this. Thanks in advance.

edited Aug '15

I had to do this recently for a project of mine. There are 2 parts: 1) Breaking out all your text into language files, 2) Using the right language file.

1) Phalcon has built-in multi-language support, take a look at that.

2) How this is implemented depedns on your site. Often, I'll see urls like www.domain.com/en/some/page.html or www.domain.com/jp/some/page.html. The language to use can then be determined from the URL. If you have an existing site though, that may be difficult to implement. What I did for my site was have the user choose their language at log in. I then stored that language in their session, and accessed it every page load to determine what language to use. If you don't have a log in, you can set up your links similar to this: www.domain.com/language/choose/en/ and www.domain.com/language/choose/jp/. Then in your LanguageController file, in the chooseAction() method, you can simply set a session value.

You can check https://docs.phalcon.io/3.4/en/translate

I chose to store all my translations in the database for my site in norwegian and english, all fields utf8 and the mysql connection as utf8. But i made a mistake. Google recommends to implement subdomains for Multilingual Sites, not folders.