Solar comes with a built-in localization system based on PHP
arrays, where the array key is an identifier, and the value is the
replacement string. Every class in Solar has a Locale/
subdirectory; therein are translation files named for language and
country. The default is en_US.php
. The locale
file is loaded on-demand.
Every class in Solar has a locale()
method that
translates a locale key to its replacement string. As with most other
things in Solar, locale files are inherited, so if you ask for a locale
key that exists only in a parent class, Solar will work up the inheritance
chain until it finds that key.
Inside a view, you can use the getText()
helper
to get the locale strings for the application. (You can use the
locale()
method on other objects in the view to
get their translation strings.)
To modify the locale strings for the blog application, open the
Blog/Locale/en_US.php
file.
$ vim Blog/Locale/en_US.php
Change the contents of the file to the following, and save it.
<?php return array(
'ERR_NO_ID_SPECIFIED' => 'No ID was specified',
'ERR_NO_RECORDS' => 'No records found.',
'ERR_NO_SUCH_ITEM' => 'That item does not exist.',
'HEADING_ADD' => 'Add New Article',
'HEADING_DELETE' => 'Delete This Article?',
'HEADING_DRAFTS' => 'Draft Articles',
'HEADING_EDIT' => 'Edit Article',
'HEADING_INDEX' => 'Published Articles',
'TEXT_DELETED' => 'Deleted the article.',
'TITLE_ADD' => 'Blog : Add New Article',
'TITLE_DELETE' => 'Blog : Delete Article',
'TITLE_DRAFTS' => 'Blog : Draft Articles',
'TITLE_EDIT' => 'Blog : Edit Article',
'TITLE_INDEX' => 'Blog : Published Articles',
);
Now when you go to the application, you should see the translated locale strings.