Created
June 27, 2015 06:56
-
-
Save Grawl/ba8f39b8398791c6a67e to your computer and use it in GitHub Desktop.
L10n on php + gettext
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#: 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/locale/en_US/LC_MESSAGES/bridges.mo | |
/locale/en_US/LC_MESSAGES/bridges.po |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$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); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$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