English 中文(简体)
如何最佳地翻译铁路运输路线中的红 the
原标题:What is the best way to translate slugs in Rails routes

I m trying to achieve full internationalization of my routes in a Rails3.1 app. I m already using Francesc Pla s rails-translate-routes to localize route actions and resources. The last step is to be able to translate slugs for some of my models.

有待翻译的道路:

http://myhost.com/products/pharmacy --> http://myhost.com/productos/farmacia

我有一张表格的通道。

# routes.rb
match  products/:category_slug  => "products#index"

我有一个示范类,其实例为:#<Category id: 1, slug: “pharmacy”>, I do find_by_slug 主计长。

关于如何翻译<代码>的任何想法:类别_slug 部分路线?

问题回答

如我所知,只要你用<密码>I18正确命名空间,你就可以直接从你的控制器打电话给翻译员。

• 贵产品 主计长可以包含如下内容:

class ProductsController < ApplicationController
  def index
    i18n_slug = I18n.t("locale.category.#{params[:category_slug]}")
    @category = Category.find_by_slug(i18n_slug)
  end
end

You should probably inform yourself as to potential security risks of passing the params directly into the translation engine, though I m not aware of any. You might also consider moving that into a before filter or into the application controller if it will be used in multiple controller actions.





相关问题
How does gettext handle dynamic content?

In php (or maybe gettext in general), what does gettext do when it sees a variable to dynamic content? I have 2 cases in mind. 1) Let s say I have <?=$user1?> poked John <?=$user2?>. ...

Explain the Need for Mutexes in Locales, Please

Reading the question Why doesn’t C++ STL support atoi(const string& ) like functions?, I encountered a comment which warned that GCC (at least) has a bug that can slow down multi-threaded ...

How does Vistalizer work

How does Vistalizer manage to override the language limit in Windows Vista Home edition. Which api s does it use to allow installation of Multiple language packages.

Localized exceptions (within a Struts2 app)

I am developing a Struts 2 application with support for multiple languages. If one of the domain objects needs to throw an exception, how can it do so in such a way that the error message is no ...

Rails Globalize plugin help

Has anyone gotten the Globalize plugin to work Rails 2.3.2 or later? If so, could you direct me to some useful info?

热门标签