rails-i18n

How do I recursively flatten a YAML file into a JSON object where keys are dot separated strings?

放肆的年华 提交于 2019-12-10 13:19:51
问题 For example if I have YAML file with en: questions: new: 'New Question' other: recent: 'Recent' old: 'Old' This would end up as a json object like { 'questions.new': 'New Question', 'questions.other.recent': 'Recent', 'questions.other.old': 'Old' } 回答1: Since the question is about using YAML files for i18n on a Rails app, it's worth noting that the i18n gem provides a helper module I18n::Backend::Flatten that flattens translations exactly like this: test.rb : require 'yaml' require 'json'

Rails 4 multidomain application with locale set for each domain i18n locale

落花浮王杯 提交于 2019-12-10 08:40:37
问题 In a Rails 4 multidomain app, I would need a set of locale files for 4 languages for each domain (3 domains total). Some of the translations overlap between the domains but some of them are very specific, so I am thinking about a structure that would go somewhat like this: config/locales/en.yml ..fr.yml ..de.yml ..it.yml #is picked up by all domains config/locales/domain1/en.yml ..fr.yml ..de.yml ..it.yml #is picked up by domain 1 config/locales/domain2/en.yml ..fr.yml ..de.yml ..it.yml #is

Page needs to be refreshed after switching locale for Blacklight label to translate

£可爱£侵袭症+ 提交于 2019-12-10 02:29:19
问题 I am trying to create an Arabic version of a Rails app which is based on Blacklight. Here's the problem I am facing: When I switch the language, everything translates perfectly EXCEPT the Blacklight labels. It's only when I refresh the page that the labels get translated. This is the label I want to display: "ترتيب حسب عام" (Translation: Sort by Year) But this is what I am getting currently: "Year ترتيب حسب" The same issue happens when switching back to English from Arabic - the label

undefined method `t' for Admin::FaqsController:Class

蓝咒 提交于 2019-12-10 00:51:31
问题 in my project i have controller in namespace admin and I'm using breadcrumbs_on_rails to build breadcrums. My controller looks like: module Admin class FaqsController < Admin::ApplicationController include FaqsHelper load_and_authorize_resource add_breadcrumb t('faqs.faqs_list') , :faqs_path #this line makes the problem def index @faqs = @faqs add_breadcrumb t('faqs.faqs_list') end def new add_breadcrumb t('faqs.new') end #other code ommitted end end i can use t method in new, edit and other

ActionController::UrlGenerationError in Devise::Registrations#create

泄露秘密 提交于 2019-12-08 11:37:21
问题 I'm newbie in Rails and I don't know what to do with tis error, please help (with explanation): ActionController::UrlGenerationError in Devise::Registrations#create Showing /home/ubuntu/workspace/mamchut418/app/views/devise/mailer/confirmation_instructions.html.erb where line #5 raised: No route matches {:action=>"create", :confirmation_token=>"24GGcednzrEXEzaR82AC", :controller=>"devise/confirmations"} missing required keys: [:locale] Extracted source (around line #5): 3 | <p><%= _('You can

I18n localization time format for spanish translation

半城伤御伤魂 提交于 2019-12-08 11:29:54
问题 I am using I18n for localizing a rails application, and i came across a situation which involves time format using I18n. the date and time format displaying is as follows: "Tuesday, July 11, 2017" for time : 2017-07-11 12:30:00 +0530 for localizing i am using en.yml and es.yml with both time formats as shown below: en: time: formats: long: '%A, %B %d, %Y' short: '%b %d, %Y' and in model i am using I18n.l(raw_date.to_time, format: :long) , this working fine for english with result "Tuesday,

Rails: Model.human_attribute_name :field should raise an error when translation not found? (Maybe caused by state_machine?)

不羁的心 提交于 2019-12-08 01:54:45
问题 We often stumble over untranslated model attributes in our application. They most often come because an attribute was renamed or something like this. It would be really helpful to have I18n raise an error when Model.human_attribute_name :field doesn't find a translation. Is there a way to achieve this? Update : It seems there's some other problem. here are my I18n settings: I18n.enforce_available_locales = false config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb

Rails I18n translations scoping

早过忘川 提交于 2019-12-07 09:03:30
问题 Writing a fully translated app can become tedious. Is there a way to set a default translation scope for the current context ? Example : I am writing inside a partial _deadlines.html.erb in the show.html.erb action of my ProjectsController Now because I am trying to be a good programmer, I am scoping all my translations. I would like to produce the following tree projects: deadlines: now: "Hurry the deadline is today !" .... How can I make it less tedious than writing each time the full scope

Inheriting Rails i18n validation error messages in the subclass

我的未来我决定 提交于 2019-12-07 04:44:52
问题 What I understand Suppose I have a class with a handy validation like: User < ActiveRecord::Base validates :username, :format => {/regex/}, :message => :name_format end In this case, I can use i18n to make the error message translatable, by including the following in my /config/locals/en.yml : en: activerecord: errors: models: user: attributes: username: name_format: 'has the way-wrong format, bro!' This is fine and generally really handy. What I want to know: My question is: What happens

Rails: Model.human_attribute_name :field should raise an error when translation not found? (Maybe caused by state_machine?)

早过忘川 提交于 2019-12-06 10:37:05
We often stumble over untranslated model attributes in our application. They most often come because an attribute was renamed or something like this. It would be really helpful to have I18n raise an error when Model.human_attribute_name :field doesn't find a translation. Is there a way to achieve this? Update : It seems there's some other problem. here are my I18n settings: I18n.enforce_available_locales = false config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')] config.i18n.default_locale = 'de-CH' config.i18n.available_locales = ['de', 'de-CH', 'en'] config