【问题标题】:Best practice in making Rails applications multilingual使 Rails 应用程序多语言化的最佳实践
【发布时间】:2014-02-22 02:30:56
【问题描述】:

大家好:D 我刚开始学习 Rails,目前我有一个问题。

我正在构建一个需要翻译成 4 种语言的 Rails 网站。什么是最实用和最方便的方法?

我已阅读主要目标是为每种语言创建单独的文件夹并复制每种语言的所有视图。但是我的控制器内仍然会有notice 英文消息,所以我将如何处理它。 Routes 也是我关心的问题。对于 4 个不同的翻译视图,我是否应该有 4 条不同的路线。

您建议如何处理此问题?我没有在网上找到任何具体的东西。

感谢您的建议!

【问题讨论】:

    标签: ruby-on-rails html ruby-on-rails-4 multilingual


    【解决方案1】:

    对于您的通知消息,您可以这样做

      def create
        if user.save
          flash[:notice] = t(:user_was_successfully_created)
          redirect_to users_users_path
        else
          render :new
        end
      end
    

    你应该有 4 种不同的路线

    Rails 国际化 (I18n) API

    看看这个链接http://guides.rubyonrails.org/i18n.html

    Rails 国际化 (I18n) API

    Ruby on Rails(从 Rails 2.2 开始)附带的 Ruby I18n(国际化简写)gem 提供了一个易于使用和可扩展的框架,用于将您的应用程序翻译成英语以外的单一自定义语言,或提供您的应用程序中的多语言支持。

    “国际化”过程通常意味着从您的应用程序中抽象出所有字符串和其他特定于语言环境的位(例如日期或货币格式)。 “本地化”过程意味着为这些比特提供翻译和本地化格式。1

    因此,在将 Rails 应用程序国际化的过程中,您必须:

    Ensure you have support for i18n.
    Tell Rails where to find locale dictionaries.
    Tell Rails how to set, preserve and switch locales.
    

    在本地化应用程序的过程中,您可能需要做以下三件事:

    Replace or supplement Rails' default locale — e.g. date and time formats, month names, Active Record model names, etc.
    Abstract strings in your application into keyed dictionaries — e.g. flash messages, static text in your views, etc.
    Store the resulting dictionaries somewhere.
    

    本指南将引导您了解 I18n API,并包含有关如何从一开始就国际化 Rails 应用程序的教程。

    阅读本指南后,您将知道:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-18
      • 1970-01-01
      • 2011-01-30
      • 2017-06-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多