Magento ::从javascript文件翻译文本 [英] Magento :: Translate text from javascript files

查看:121
本文介绍了Magento ::从javascript文件翻译文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Magento使用系统翻译模板文件中的文本:

Magento uses a system for translating text in the template files using:

$ this-> __('要翻译的文字。 ');

Mage :: helper('modulename') - > __('要翻译的文字。');

这很有效。
但是当我向javascript文件添加文本时,我无法使用这两种方法。

This works quite well. But when I add text to a javascript file I can't use these two methods.

有没有办法可以对javascript文件的翻译做类似的事情?

Is there a way I could do a similar thing with the translations for javascript files?

推荐答案

您可以在模板文件yourfile.phtml中执行此操作。 javascript脚本js / mage / translate.js必须包含在你的html标题中(默认情况下Magento会这样做)。

You can do it in a template file yourfile.phtml. The javascript script js/mage/translate.js must be included in your html header (Magento does it by default).

<script type="text/javascript">
Translator.add('You should take care of this confirmation message!','<?php echo Mage::helper('yourmodule')->__('You should take care of this confirmation message!')?>');
</script>

编辑
您可以从Magento 1.7添加文件将jstranslator.xml放入etc /文件夹下的模块中,并设置如下字符串:

EDIT: You can since Magento 1.7 add a file jstranslator.xml into your module under the etc/ folder and set the following string like that:

<jstranslator>
    <!-- validation.js -->
    <validate-no-html-tags translate="message" module="core">
        <message>HTML tags are not allowed</message>
    </validate-no-html-tags>
    <validate-select translate="message" module="core">
        <message>Please select an option.</message>
    </validate-select>
</jstranslator>

然后翻译字符串就像你为PHP做的那样感谢CSV文件
这个,将将翻译添加到javascript代码,如下所示 var Translator = new Translate(...)

Then translate the string as you do it for PHP thanks to CSV file This, will add the translation to the javascript code like the following var Translator = new Translate(...)

这篇关于Magento ::从javascript文件翻译文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆