Tip:
Highlight text to annotate it
X
This is how to apply the internationalization patch for Hero Framework
Before starting the screencast, a little summary of the required steps:
first, download the Hero Framework code from the Hero website and unzip it in the webfolder
then download the patch from my blog and apply it
then start the installation process as usual:
add the cache folder
change the rights for the required folders
rename the config file
create the database
and finally launch the Hero Framework installation process
I'm going through these steps very quickly
I unpacked the hero framework in my webroot and, for my convenience, I rename the folder
to hero_test because my vhost is configured like that
now I get inside the hero directory and I apply the patch
then I set the rights to folders
and finally I create the database
I'm now ready to start the Hero installation process as usual
The installation process is over and I'm ready to show how to use the internationalization
Due to the internationalization patch Hero Framework now has a new toggle in the Settings
Manager which enabled or disables the localization support. If you turn it off your Hero Framework
will work exactly as it did before.
To localize the website content the theme must be modified a little. Within the patch,
I provided a modified template with localization support. The modified theme is called Electric,
so let's install it paying attention to the "install default content" and "reset my platform"
options: they must be selected.
The installation of the theme populated the database with some content. I modified the
"Welcome to Hero" static page to show how to deal with translations.
To translate content using .po files, I need to wrap sentences with the {t} block. In this
example the first sentence wrapped in the {t} block is: "If this is your first time
using"
Every single sentence marked with the {t} block must be written in the .po files. .Po
files are located in the "app/third_party/php_gettext..." folder
and this is how a .po file looks like.
The README_localization.txt file in the "locale" folder contains some tricks about .po files
that you might want to read.
When the .po file contains the translations for the sentences marked with the {t} block,
using the msgfmt program, I can create the binary .mo file which will be used by phpgettext
to translate the content.
Everything is ready to go and see what happens when I display the page. This is the "Welcome
to Hero" page and on the top right is showned a rough white box containing the languages
currently enabled. When I click on italian the text gets translated in italian and of
course the other way around when I click on english
Now what if I want to enable also the russian translation? All I have to do is to provide
a .po file containing the russian sentences and make the .mo file. Everything exactly
as I did before for the italian translation. The only difference is that, in this case,
I have to enable the language for the Hero Framework.
I go again in the "app/third_party/php_gettext..." directory and I create the .mo file for the
russian translation that I included in the patch
Then it's the time to enable the language by editing the phpgettext.php file contained
in the "app/config" folder: it's enough to add 'ru_RU' as a new item for the array $config['gettextSupportedLocales']
Now I go back to my browser and I refresh the page. The top right box now shows also
the russian language and by clicking on it I get the page in Russian
Now I want to translate some more text.
I edit the page and I wrap the sentence "Take a look around this default" in the {t} block
I update the content of the .po file
I save the post
and I recreate the .mo file
Now I just refresh my browser, I click on italian and I can see the sentence translated
That's all. I hope to have the chance in the future to work on the code to enhance the
user interface to reduce the usage of the terminal to provide a better user experience,
so ... stay tuned