Drupal7:为什么 t() 不工作?
Drupal7 : Why t() is not working?
我负责Drupal7 上的一个旧站点,我知道的太少了。该网站是双语网站 English/French。
所以在模板中,我添加了一些字段,其中包含需要翻译的字符串:
<div class="offer_content">
<span class="title" style="text-transform:uppercase;font-size:18px;"><?php echo t('Our Firma').(': ');?></span>
<?php echo html_entity_decode(t($fields['field_presentation_societe']->content)); ?>
<span class="title" style="text-transform:uppercase;font-size:18px;"><?php echo t('Job presentation').(': ');?></span>
<?php echo html_entity_decode(t($fields['body']->content));?>
<span class="title" style="text-transform:uppercase;font-size:18px;"><?php echo t('Skills').(': ');?></span>
<?php echo html_entity_decode(t($fields['field_profil_recherche']->content)); ?>
但是,在法语中,这让我显示 "Our Firma" 和 "Skills" ... 而不是翻译?为什么?
谢谢你:)
变量在设计上是不可翻译的。见 t
-docs:
Translating Variables
You should never use t()
to translate variables, such as calling
t($text);
, unless the text that the variable holds has been passed through t()
elsewhere (e.g., $text is one of several translated literal strings in
an array). It is especially important never to call
t($user_text);
, where $user_text is some text that a user entered - doing that can
lead to cross-site scripting and other security problems. However, you
can use variable substitution in your string, to put variable text
such as user names or link URLs into translated text. Variable
substitution looks like this:
$text = t("@name's blog", array(
'@name' => format_username($account),
));
Basically, you can put variables like @name into your string, and t()
will substitute their sanitized values at translation time. (See the
Localization API pages referenced above and the documentation of
format_string() for details about how to define variables in your
string.) Translators can then rearrange the string as necessary for
the language (e.g., in Spanish, it might be "blog de @name").
所以您可以改为使用 Entity Translation 使这些字段可翻译。然后您将能够翻译您的内容,并且将根据在匹配语言中添加到字段中的值打印正确的翻译。
或使用 i18n_string()
,参见 https://drupal.stackexchange.com/a/184584
我负责Drupal7 上的一个旧站点,我知道的太少了。该网站是双语网站 English/French。 所以在模板中,我添加了一些字段,其中包含需要翻译的字符串:
<div class="offer_content">
<span class="title" style="text-transform:uppercase;font-size:18px;"><?php echo t('Our Firma').(': ');?></span>
<?php echo html_entity_decode(t($fields['field_presentation_societe']->content)); ?>
<span class="title" style="text-transform:uppercase;font-size:18px;"><?php echo t('Job presentation').(': ');?></span>
<?php echo html_entity_decode(t($fields['body']->content));?>
<span class="title" style="text-transform:uppercase;font-size:18px;"><?php echo t('Skills').(': ');?></span>
<?php echo html_entity_decode(t($fields['field_profil_recherche']->content)); ?>
但是,在法语中,这让我显示 "Our Firma" 和 "Skills" ... 而不是翻译?为什么?
谢谢你:)
变量在设计上是不可翻译的。见 t
-docs:
Translating Variables
You should never use
t()
to translate variables, such as callingt($text);
, unless the text that the variable holds has been passed through t() elsewhere (e.g., $text is one of several translated literal strings in an array). It is especially important never to call
t($user_text);
, where $user_text is some text that a user entered - doing that can lead to cross-site scripting and other security problems. However, you can use variable substitution in your string, to put variable text such as user names or link URLs into translated text. Variable substitution looks like this:
$text = t("@name's blog", array( '@name' => format_username($account), ));
Basically, you can put variables like @name into your string, and t() will substitute their sanitized values at translation time. (See the Localization API pages referenced above and the documentation of format_string() for details about how to define variables in your string.) Translators can then rearrange the string as necessary for the language (e.g., in Spanish, it might be "blog de @name").
所以您可以改为使用 Entity Translation 使这些字段可翻译。然后您将能够翻译您的内容,并且将根据在匹配语言中添加到字段中的值打印正确的翻译。
或使用 i18n_string()
,参见 https://drupal.stackexchange.com/a/184584