【问题标题】:How do I deal with locale of URL in Spree i18n?如何处理 Spree i18n 中 URL 的语言环境?
【发布时间】:2019-05-04 06:16:30
【问题描述】:

我想像这样修复 url 重复的语言环境。 http://localhost:3000/ja/shop/ja/products/apache-baseball-jersey/'

前几天我在我的 Rails 应用程序上设置了 spree_i18n。 并像这样设置 Gemfile。

# Spree
gem 'spree', '~> 3.7.2'
gem 'spree_gateway', '~> 3.4'
gem 'spree_i18n', github: 'spree-contrib/spree_i18n'
gem 'spree_globalize', github: 'spree-contrib/spree_globalize'
gem 'spree_paypal_express', github: 'spree-contrib/better_spree_paypal_express'

还有,这是我的路线。

Rails.application.routes.draw do
scope "(:locale)", locale: /en|ja/ do
   get '/' => 'frontpage#index'
   mount Spree::Core::Engine, at: '/shop

我的默认语言环境是英语,支持的语言环境是日语。 理想的网址是“https://somedomain/(locale)/product”。

那我该怎么办呢?

【问题讨论】:

标签: ruby-on-rails spree


【解决方案1】:

语言环境重复

在我看来,Spree 的引擎和spree_i18n 已经处理了基于语言环境的路由。

删除 scope "(:locale)", locale: /en|ja/ 应该会删除重复项。

删除“/shop”

如果您希望“https://somedomain/(locale)/product”成为您的网址,那么这意味着从其中删除“/shop”。您可以通过将 spree 的引擎直接安装在根目录上来做到这一点:mount Spree::Core::Engine, at: '/。请注意,这样做,您自己添加的任何路线都可能与引擎定义的路线发生冲突。

【讨论】:

  • 谢谢!这可能会有所帮助。我不得不为我之前写的东西道歉。我想制作 url 'somedomain/(locale)/shop/product' 。在这种情况下,我是否必须将其保留为 'mount Spree::Core::Engine, at: '/shop.' ?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-03
  • 1970-01-01
  • 2019-12-17
  • 2020-07-07
相关资源
最近更新 更多