i18n: gettext + Zend_Translate - 命名空间/将字符串分组在一起?

发布于 2024-08-12 04:20:11 字数 815 浏览 5 评论 0原文

我正在将当前框架的 i18n 方法从将语言字符串存储在数组中的 Localization 类更新为 gettext + Zend_Translate

有一种情况让我感到困惑,单字符串输出很简单,但使用我当前的方法,我将某些字符串分组在一起,用于城市、州、前缀等集合,以便可以轻松操作它们并将其转换为 html (例如下拉选项)。

我是否别无选择,只能按顺序存储如下数组,以便它们仍然分组在一起?或者在使用 gettext 时我是否错过了某种方法,它允许我以更方便的方式执行此操作?

class Localization
{
    var $prefixes = array(
        ""=>"Prefix", 
        "Mr."=>"Mr.", 
        "Mrs."=>"Mrs.", 
        "Ms."=>"Ms.", 
        "Dr."=>"Dr."
    );

重申一下,我希望能够基本上保留我的方法,其中调用如下使用:

<label for="prefixes"><?php echo $local->_('Prefix');?></label>
<?php echo Class::grab_prefixes(); // generates a dropdown of prefixes ?>

这将从本地化字符串集合中获取包括文本值和实际表单值的前缀集合。

我目前仍然依赖数组,然后对它们应用 Zend_Translate 调用。

I'm updating my current framework's i18n method from a Localization class that stores language strings in arrays to gettext + Zend_Translate.

There's a certain situation which leaves me puzzled, single string outputting is simple but using my current method I'm grouping certain strings together, for collections such as cities, states, prefixes in order such that they can be manipulated and transformed easily into html ( such as dropdown options ).

Would I have no choice but to store arrays such as the one below in order such that they are still grouped together? Or is there some sort of method I'm missing out on when using gettext, which allows me to do this in a more convenient fashion?

class Localization
{
    var $prefixes = array(
        ""=>"Prefix", 
        "Mr."=>"Mr.", 
        "Mrs."=>"Mrs.", 
        "Ms."=>"Ms.", 
        "Dr."=>"Dr."
    );

To reiterate, I want to be able to basically retain my method, in which the invocation is used as such:

<label for="prefixes"><?php echo $local->_('Prefix');?></label>
<?php echo Class::grab_prefixes(); // generates a dropdown of prefixes ?>

And this would grab a collection of prefixes including text values and actual form values from a localized string collection.

I'm currently still relying on the arrays and then applying the Zend_Translate invocation on them.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

番薯 2024-08-19 04:20:11

实际上重新思考它,因为我有选择地将某些字符串分组在一起,以便它们成为 唯一可行且实用的方法可能会存储它们,因为我已经将它们作为数组存储。

这就是其他框架为州、城市、国家生成完整下拉菜单的方式……不是吗?

Actually re-thinking about it, because I'm selectively grouping certain strings together in order such that they become <option value="value">text</option> the only feasible and practical way would probably be to store them as I already have them as arrays.

This is how other frameworks generate entire dropdowns for states, cities, countries.. no?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文