以下示例适用于使用Apache的Mac OS X,即我将已翻译的字符串回显.但是在使用lighttpd的Ubuntu上,我得到原始文本"非活动帐户".我已经尝试了各种各样的环境varialbes组合而没有任何运气.它不是文件权限,因为我可以回显.mo文件的内容.
<?php
//$locale = 'sv_SE.UTF-8';
$locale = 'sv_SE';
$dir = dirname(__FILE__);
// File permission is apparantly not a problem as this works...
//echo file_get_contents($dir . '/sv_SE/LC_MESSAGES/flattr.mo');
putenv("LANG=$locale");
putenv("LANGUAGE=$locale");
putenv("LC_ALL=$locale");
putenv("LC_MESSAGES=$locale");
setlocale(LC_ALL, $locale);
setlocale(LC_MESSAGES, $locale);
//setlocale(LANG, $locale);
//setlocale(LANGUAGE, $locale);
bindtextdomain('flattr', $dir);
//bind_textdomain_codeset("flattr", 'UTF-8');
textdomain('flattr');
echo _("Inactive account");
?>
Run Code Online (Sandbox Code Playgroud)
有人有主意吗?
我想在php 5.5中使用php gettext扩展(在win2008服务器上,使用IIS7).我这样做:
<?php
$locale = "es";
if (isSet($_GET["locale"])) $locale = $_GET["locale"];
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain("messages", "./locale");
textdomain("messages");
echo gettext("Hello world");
?>
Run Code Online (Sandbox Code Playgroud)
使用此文件夹结构:
locale/es/LC_MESSAGES/messages.mo
Run Code Online (Sandbox Code Playgroud)
但它总是只返回Hello世界而不是正确的翻译现在(基于我缺乏西班牙语技能)是在messages.po文件中:
msgid ""
msgstr ""
"Project-Id-Version: TestXlations\n"
"POT-Creation-Date: 2014-04-19 08:15-0500\n"
"PO-Revision-Date: 2014-04-19 09:18-0500\n"
"Language-Team: \n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.6.3\n"
"X-Poedit-Basepath: .\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-SearchPath-0: c:/dev\n"
msgid "Hello world"
msgstr "Hola World"
Run Code Online (Sandbox Code Playgroud)
这从cmd行和IIS失败.所以我看到gettext调用等并执行它但它没有读取翻译文件.我该如何进一步调试?即使删除翻译文件,我也会得到相同的行为.
我在这里搜索了谷歌!但是没有成功找到解决方案,我真的是使用python的noob但是能够安装与yum分开的python.
现在,我需要重新编译OSQA系统的语言包,但是得到以下消息:
Error: errors happened while running xgettext on __init__.py
xgettext: ./Django-1.2.3/tests/regressiontests/views/__init__.py:1: Unknown encoding "utf8". Proceeding with ASCII instead.
xgettext: Non-ASCII string at ./Django-1.2.3/tests/regressiontests/views/__init__.py:7.
Please specify the source encoding through --from-code or through a comment
as specified in http://www.python.org/peps/pep-0263.html.
Run Code Online (Sandbox Code Playgroud)
我试过,但没有成功解决它,在manage.py文件中设置utf-8编码,但也没有成功.
有人能帮我解决一下吗?:(
谢谢,最好的问候!
我有一个带有国际化字符串的python项目.我修改了源代码并更改了字符串的行,即在pot和po文件中,字符串的行不指向正确的行.
那么如何将po和pot文件更新为文件中的新字符串位置.
我需要在JavaScript中为浏览器端翻译开发或找到某种轻量级类似gettext的库.如果我想转换服务器端,node.js最好使用相同的库.
1)但是,使用.po文件和JavaScript gettext库的优缺点是什么?
(与JSON和jQuery Globalize或类似的相反?)
2)是否有任何工作流/服务允许翻译众包,可以导出为JavaScript i18n库(gettext实现,Globalize.js等)可以使用的格式(.po/json)?
请参阅此_n();
函数示例(http://codex.wordpress.org/Function_Reference/_n):
sprintf( _n('%d comment.', '%d comments.', $number, 'text-domain'), $number );
用英语讲:
1 Comment
2 Comments
Run Code Online (Sandbox Code Playgroud)
在波兰语等语言中有不同的模式和多种复数形式:
1 Komentarz
2 Komentarze
3 Komentarze
4 Komentarze
5 Komentarzy
6 Komentarzy
...
21 Komentarzy
22 Komentarze
23 Komentarze
24 Komentarze
25 Komentarzy
...
31 Komentarzy
32 Komentarze
...
91 Komentarzy
92 Komentarze
...
111 Komentarzy
112 Komentarzy (!)
...
121 Komentarzy
122 Komentarze
Run Code Online (Sandbox Code Playgroud)
如果他们的语言支持多种复数形式,我正在寻找一些方法来让翻译人员设置他们自己的模式.您能想到任何有创意的PHP方法吗?
我能想到的一些解决方案(但仍然是翻译人员无法设置任何模式):
if($number == 1){
$message = __(‘1 Komentarz’ , ‘text-domain’);
}else if($number == 2){
$message …
Run Code Online (Sandbox Code Playgroud) 我在android中有一个EditText供用户输入他们的AGE.它设置为inputType = phone.我想知道是否有办法检查这个EditText是否为空.
我已经看过这个问题:检查EditText是否为空.但它没有解决inputType = phone的情况.
这些,我已经检查过并且不起作用:
(EditText) findViewByID(R.id.age)).getText().toString() == null
(EditText) findViewByID(R.id.age)).getText().toString() == ""
(EditText) findViewByID(R.id.age)).getText().toString().matches("")
(EditText) findViewByID(R.id.age)).getText().toString().equals("")
(EditText) findViewByID(R.id.age)).getText().toString().equals(null)
(EditText) findViewByID(R.id.age)).getText().toString().trim().length() == 0
(EditText) findViewByID(R.id.age)).getText().toString().trim().equals("")
and isEmpty do not check for blank space.
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助.
我有以下情况:
我要翻译的一个产品,有两个独立的网站,一个用于管理员,一个用于客户.
代码库是CakePHP.
两个站点彼此完全分离,它们是完整的CakePHP站点.
而且它们都有很多共同点.
因此,使用CakePHP,我为每个站点生成.pot文件,但我很乐意为翻译者提供一个文件,两个.pot文件中都有唯一的字符串.
他们会给我一个带有两个网站字符串的.po文件,我只是将同一个文件复制到两个网站,所以我会有.po文件,其中包含代码不会使用的额外字符串,但是应该不是问题.
所以问题基本上是......我如何合并两个.pot文件?
你知道有什么工具让我这么做吗?我真的很想避免写自己的.
这些是我上面谈到的评论:
#: \controllers\accounts_controller.php:118
#: \controllers\customer_documents_controller.php:75
msgid "Parent Customer not specified"
msgstr ""
Run Code Online (Sandbox Code Playgroud) 我正在开发一个多语言的PHP Web应用程序,我有很长的( - )文本,我需要用gettext进行翻译.这些是电子邮件模板(通常很短,但仍有几行)和视图模板的一部分(较长的描述性文本块).这些文本将包括一些简单的HTML(强调粗体/斜体,可能是这里或那里的链接).模板是PHP脚本,其输出被捕获.
问题是gettext对于处理较长的文本似乎非常笨拙.较长的文本通常会比短文本有更多的变化 - 我可以更改msgid并确保在所有翻译中更新它(当msgid很长时可能是很多工作并且非常容易出错),或者我可以保留msgid保持不变并仅修改翻译(这会在模板中留下误导性的过时文本).另外,我已经看到了反对在gettext字符串中包含HTML的建议,但是避免它会将一个自然文本分成很多块,这将是翻译和重新组合的更大噩梦,我也看到了建议不必要的将gettext字符串拆分成单独的msgids.
我看到的另一种方法是完全忽略这些较长文本的gettext,并为每个语言环境分离外部子模板中的那些块,并且只包括当前语言环境的那个.缺点是我将gettext .po文件和位于完全不同位置的单独模板之间的转换工作分开.
由于此应用程序将在未来用作其他应用程序的起点,因此我试图提出长期的最佳方法.在这种情况下,我需要一些关于最佳实践的建议.你是如何实施类似案件的?什么结果发挥作用,结果是一个坏主意?
可能重复:
gettext如何处理动态内容?
我正在使用PHP的gettext.我想翻译一个有变量的句子.这可能吗?
例如,用英语:
Are you sure you want to block Alice?
(其中"Alice"是用户的名字.)
但是,在德语中,主语并未出现在句子的末尾.
Sind Sie sicher, dass Sie Alice blockieren?
在messages.po中,我有
msgid "BLOCK"
msgstr "Are you sure you want to block"
Run Code Online (Sandbox Code Playgroud)
但我认为无法传递一个或多个变量.这可能吗?
gettext ×10
localization ×4
php ×4
po ×2
python ×2
android ×1
django ×1
email ×1
javascript ×1
longtext ×1
node.js ×1
php-gettext ×1
setlocale ×1
templates ×1
translation ×1
ubuntu ×1
wordpress ×1
xgettext ×1