-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodifier.getText.php
More file actions
executable file
·60 lines (51 loc) · 1.93 KB
/
modifier.getText.php
File metadata and controls
executable file
·60 lines (51 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* @author Guido K.B.W. Üffing <info ueffing net>
* @license GNU GENERAL PUBLIC LICENSE Version 3
*
* Smarty plugin
* Type: modifier
* Name: smarty_modifier_gettext
* Version: 1
* Date: 2013-07-19
* @see https://blog.ueffing.net/post/2013/07/19/php-smarty-a-modifier-for-internationalization-tool-gettext/
*
* @access public
* @var $sString String to be translated
* @var $sDomain e.g. "backend"; means the File (backend.mo) which will be consulted for Translation
* @var $sLang Translation into a certain Language, e.g. "de_DE"
* @return string translated String
*/
function smarty_modifier_getText ($sString, $sDomain = 'backend', $sLang = 'de_DE')
{
if (empty($sString))
{
return gettype ($sString);
}
// requires installation of php module: php{Version}-intl (and maybe libicu52)
//
// This function needs a "BCP 47 compliant language tag"
// what is per definition, using a dash instead of an underscore
// @see http://www.php.net/manual/de/locale.setdefault.php
// http://en.wikipedia.org/wiki/IETF_language_tag
\Locale::setDefault(str_replace('_', '-', $sLang));
// Setting the proper Codeset
// here, don't use a dash '-'
$sCodeset = 'UTF8';
putenv('LANG=' . $sLang . '.' . $sCodeset);
putenv('LANGUAGE=' . $sLang . '.' . $sCodeset);
// set Codeset
bind_textdomain_codeset($sDomain, $sCodeset);
// name the Place of Translationtables
// That is where your Translationfolders reside
bindtextdomain($sDomain, '/tmp'); # flush first
bindtextdomain($sDomain, 'PATH_TO_MY_LANGUAGES_FOLDER');
// set locale
setlocale(LC_MESSAGES, ""); # flush first
setlocale(LC_MESSAGES, $sLang.'.'.$sCodeset);
// Translation will be loaded from
// e.g.: /var/www/App/languages/de_DE/LC_MESSAGES/backend.mo
textdomain($sDomain);
// return, so that further modifiers could handle it
return gettext($sString);
}