使用 mongoid 转换 Rails 中的模型属性的方法是什么?

发布于 2024-09-14 04:25:50 字数 98 浏览 6 评论 0原文

我在 mongoid 和模型翻译方面遇到问题。当我尝试在模型上使用 mongoDB 时,我不知道如何翻译属性和模型名称。它通常位于 *.yml 文件中,但这次不起作用。有什么想法吗?

I've problem with mongoid and model translations. When I'm trying use mongoDB on my model I haven't idea to translate attributes and model name. It's normally in *.yml files but in this time this doesn't work. Any ideas?

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

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

发布评论

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

评论(4

以往的大感动 2024-09-21 04:25:50

“activemodel”的变体对我不起作用。但。

这个变体对我有用:

 en:
  mongoid:
    errors:
      models:
        user:
          attributes:
            email:
              blank: "You have to give me your e-mail address"
              not_found: "e-mail address not found in list of members"
              #...
    attributes:
      user:
        email: "Email address"
        name: "Your nickname"
        #...

从这里

Variant with "activemodel" does not work for me. But.

This variant worked for me:

 en:
  mongoid:
    errors:
      models:
        user:
          attributes:
            email:
              blank: "You have to give me your e-mail address"
              not_found: "e-mail address not found in list of members"
              #...
    attributes:
      user:
        email: "Email address"
        name: "Your nickname"
        #...

From here

彼岸花ソ最美的依靠 2024-09-21 04:25:50

在 yml 文件中尝试这个(在我的例子中是 config/locales/pt-BR.yml):

 activemodel:
    attributes:
      [model_name]:
        [attribute1]: "[translation1]"
        [attribute2]: "[translation2]"
        [attribute3]: "[translation3]"

为我工作,使用 mongoid 2.0.0.beta.17 和rails 3.0.0

Try this in the yml file (config/locales/pt-BR.yml in my case):

 activemodel:
    attributes:
      [model_name]:
        [attribute1]: "[translation1]"
        [attribute2]: "[translation2]"
        [attribute3]: "[translation3]"

Worked for me, using mongoid 2.0.0.beta.17 and rails 3.0.0

旧人 2024-09-21 04:25:50

像这样使用:

mongoid:
  attributes:
    article:
      title: "Article title"

检查这个:https://gist.github.com/lurkermike/1596505

Use like this:

mongoid:
  attributes:
    article:
      title: "Article title"

Check this one: https://gist.github.com/lurkermike/1596505

彼岸花ソ最美的依靠 2024-09-21 04:25:50

如果你使用引擎,你有模型的命名空间

en:
  activerecord:
    models:
      'my_engine/mymodel':
        one: TranslatedMyModel
        other: TranslatedMyModels
    attributes:
      'my_engine/mymodel':
        myattribute: translated attribute

,或者如果你使用 mongoid

en:
  mongoid:
    models:
      'my_engine/mymodel':
        one: TranslatedMyModel
        other: TranslatedMyModels
    attributes:
      'my_engine/mymodel':
        myattribute: translated attribute

我使用来自 这个问题。

If you use engines you have o namespace the model

en:
  activerecord:
    models:
      'my_engine/mymodel':
        one: TranslatedMyModel
        other: TranslatedMyModels
    attributes:
      'my_engine/mymodel':
        myattribute: translated attribute

or if you use mongoid

en:
  mongoid:
    models:
      'my_engine/mymodel':
        one: TranslatedMyModel
        other: TranslatedMyModels
    attributes:
      'my_engine/mymodel':
        myattribute: translated attribute

I solved it using comments from this issue.

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