增加多语言控制变量

例如:
将语言文件en_US.mo放置在/usr/langs目录下(没有创建的需要新建)
然后在config.inc.php里设置添加代码 define('__TYPECHO_LANG__', 'en_US'); ,即可将语言设置为en_US
This commit is contained in:
joyqi
2014-02-28 10:53:03 +08:00
parent 6de401ab49
commit 930c595ae5
6 changed files with 20 additions and 6 deletions

3
.gitignore vendored
View File

@@ -17,6 +17,9 @@
*.exp
*.pdb
*.rar
*.mo
*.po
*.pot
.smbdelete*
*.sublime*
.sass-cache

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "usr/langs"]
path = usr/langs
url = https://github.com/typecho/languages.git

View File

@@ -27,6 +27,7 @@ package:
rm -Rf build/admin/img/editor
rm -Rf build/admin/img/icons
rm -Rf build/admin/img/icons-2x
rm -Rf build/usr/langs/*
mkdir build/usr/uploads/
chmod 777 build/usr/uploads/
tar -cvvzf build.tar.gz build/

1
usr/langs Submodule

Submodule usr/langs added at 4d8b7cbf41

View File

@@ -73,13 +73,13 @@ class Typecho_I18n
* 初始化语言文件
*
* @access private
* @return boolean
*/
private static function init()
{
/** GetText支持 */
self::$_loaded = new Typecho_I18n_GetTextMulti(self::$_lang);
return true;
if (false === self::$_loaded && self::$_lang && file_exists(self::$_lang)) {
self::$_loaded = new Typecho_I18n_GetTextMulti(self::$_lang);
}
}
/**
@@ -91,7 +91,7 @@ class Typecho_I18n
*/
public static function translate($string)
{
self::$_lang && empty(self::$_loaded) && self::init();
self::init();
return self::$_lang ? self::$_loaded->translate($string) : $string;
}
@@ -105,7 +105,7 @@ class Typecho_I18n
*/
public static function ngettext($single, $plural, $number)
{
self::$_lang && empty(self::$_loaded) && self::init();
self::init();
return self::$_lang ? self::$_loaded->ngettext($single, $plural, $number) : ($number > 1 ? $plural : $single);
}

View File

@@ -23,7 +23,13 @@ class Widget_Init extends Typecho_Widget
public function execute()
{
/** 对变量赋值 */
$options = $this->widget('Widget_Options');
$options = $this->widget('Widget_Options');
/** 语言包初始化 */
if (defined('__TYPECHO_LANG__')) {
$dir = defined('__TYPECHO_LANG_DIR__') ? __TYPECHO_LANG_DIR__ : __TYPECHO_ROOT_DIR__ . '/usr/langs';
Typecho_I18n::setLang($dir . '/' . __TYPECHO_LANG__ . '.mo');
}
/** cookie初始化 */
Typecho_Cookie::setPrefix($options->rootUrl);