Ruby on Rails inspired I18n solution for PHP applications.
You can use this class together with YAML-files to accomplish translation throughout your application.
Enjoy!
- PHP >= 5.3
- LibYAML (only tested 0.1.5)
Make sure you have the following constants defined in your application somewhere:
DEFAULT_LOCALE = "" # the default locale.
DIR_LOCALE = "" # full path to your locales.
<?php
define("DEFAULT_LOCALE", "en");
define("DIR_LOCALE", "/var/www/config/locales/");
require_once("i18n.php") // you should probably use an autoloader
# en
echo "Welcome ".I18N::t("user.name");
echo I18N::t("why.is.this.so.cool");
echo I18N::t("have_fun");
# other languages (assuming "sv" here):
echo "Welcome ".I18N::t("user.name", "sv");
echo I18N::t("why.is.this.so.cool", "sv");
echo I18N::t("have_fun", "sv");
?>
en:
user:
name: Karl Metum
why:
is:
this:
so:
cool: I don't know..
have_fun: Have fun!
sv:
user:
name: Karl Metum
why:
is:
this:
so:
cool: Jag vet inte..
have_fun: Ha så kul!
Welcome Karl Metum.
I don't know..
Have fun!
Welcome Karl Metum.
Jag vet inte..
Ha så kul!
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request