Skip to content

Instantly share code, notes, and snippets.

@Grawl
Created June 27, 2015 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Grawl/ba8f39b8398791c6a67e to your computer and use it in GitHub Desktop.
Save Grawl/ba8f39b8398791c6a67e to your computer and use it in GitHub Desktop.
L10n on php + gettext
Options +Includes +FollowSymLinks -Indexes
AddHandler server-parsed .shtml
DirectoryIndex index.php index.html
AddDefaultCharset UTF-8
CookieTracking on
CookieExpires "1 years"
# default php version is 5.x.x
# uncomment next line to use 4.4.9
# AddType application/x-httpd-php44 php
RewriteEngine On
RewriteRule ^en index.php?locale=en_US [L]
RewriteRule ^ru index.php?locale=ru_RU [L]
#php_value error_reporting 7
#php_flag display_errors On
#: footer.php:8 header.php:8
msgid "тарифы"
msgstr "pricing"
#: footer.php:9 header.php:9
msgid "о компании"
msgstr "about"
#: footer.php:10 header.php:6
msgid "сервис и услуги"
msgstr "our services"
#: footer.php:11 header.php:10
msgid "написать нам"
msgstr "contact us"
/locale/en_US/LC_MESSAGES/bridges.mo
/locale/en_US/LC_MESSAGES/bridges.po
<?
$locale=$_GET["locale"];
if(!isset($locale)) {
$locale="ru_RU";
}
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
$domain='bridges';
bindtextdomain($domain, './locale');
textdomain($domain);
function __($string){
echo gettext($string);
}
?>
<nav id="nav">
<ul>
<li class="section-link"><a href="#"><? __('сервис и услуги') ?></a>
</li>
<li class="section-link"><a href="#"><? __('тарифы') ?></a></li>
<li class="section-link"><a href="#"><? __('о компании') ?></a></li>
<li><a href="mailto:bridgesvl@mail.ru"><? __('написать нам') ?></a>
</li>
</ul>
</nav>
<?
$locales_ui=array(
"ru"=>array(
'link'=>'ru',
'id'=>"ru_RU",
'label'=>'Переключиться на русский',
'image'=>'flag-ru@2x.png'
),
"en"=>array(
'link'=>'en',
'id'=>"en_US",
'label'=>'Switch to engligh',
'image'=>'flag-en@2x.png'
)
);
foreach($locales_ui as $key=>$language){
$name=$key;
$href=$language['link'];
$class=array('locale-item');
if($locale==$language['id']){
array_push($class, 'active');
}
$class=implode(' ', $class);
?>
<a
href="<?= $href ?>"
class="<?= $class ?>"
>
<img
src="images/<?= $language['image'] ?>"
class="locale-item-icon"
>
</a>
<?
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment