How to translate errors and attributes of model in Rails? - ruby-on-rails

I've changed default locale of my project, and now there is the following error:
Average check translation missing: ru.activemodel.errors.models.place_restaurant.attributes.average_check.blank
Average check is ':average_check' in 'PlaceRestaurant' model. I want to change 'Average check' text for russian analogue, and add text of error. I've made 'ru.yml' file:
ru:
activerecord:
models:
place_restaurant: "Some russian analogue"
attributes:
place_restaurant:
average_check: "Some russian analogue"
But it doesn't work, average_check is still 'Average check'. How can I fix it?

An error message gives you all structure how it should looks like. Yaml should be:
ru:
activemodel:
errors:
models:
place_restaurant:
attributes:
average_check:
blank: "Не может быть пустым"
In general this error message seems to be strange for me. Are you using default presence validation?

This is how a Locale file should e like. Yo have not mentioned the "errors".
https://gist.github.com/satyatechsavy/7671560

Related

Rails i18: Translation missing error in yml files

views/ipl_mailer/confirm_doctor_form_submitted_complete.html.slim
p Dear #{#doctor.display_name},
p #{t('.thank_you')}
locales/ipl/en.yml
ipl: &ipl
ipl:
cases_review_forms:
form: &form
would_approve: "Approve(Yes/No)"
edit:
<<: *form
ipl_mailer:
confirm_doctor_form_submitted_complete:
thank_you: 'Thank you for reviewing your ClinCheck treatment plans. We have received your response and noted that all plans are approved.'
I am getting the following error:
I18n.t("thank_you")
"translation missing: en-US.thank_you"
Is it because im doing it in en.yml file instead of en-US.yml
your I18n is trying to find element in yml file inside en-US
yml file should be as below:
en:
ipl: &ipl
ipl_mailer:
confirm_doctor_form_submitted_complete:
thank_you: 'Thank you for'
then you can access it as below:
I18n.t('ipl.ipl_mailer.confirm_doctor_form_submitted_complete.thank_you')

Trouble Extracting Data with Nokogiri

I'm practicing extracting data from an XML site and I'm using Nokogiri to read and parse. I need to analyze the data but for now, I'm just trying to get an output with no success.
I have the following code:
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(open("http://www.ibiblio.org/xml/examples/shakespeare/macbeth.xml"))
doc.xpath('//PERSONA').each do |char_element|
puts char_element.text
end
I'm simply trying to read the characters off the XML website, but I'm not getting any results when I run it in the terminal. I also tried just writing a simple xpath call such as the one below:
doc.xpath("//PERSONA")
or
doc.xpath("PLAY TITLE")
And I get either an error or it simply acts as if nothing was entered.
I have put a simple function to test it so I know it's reading it. Can anyone tell me what I'm doing wrong?
You're trying to read XML file as a HTML one.
Please try that example:
doc = Nokogiri::XML(open("http://www.ibiblio.org/xml/examples/shakespeare/macbeth.xml"))
doc.xpath('//PERSONA').each{|ce| p ce.text }
"DUNCAN, king of Scotland."
"MALCOLM"
"DONALBAIN"
"MACBETH"
"BANQUO"
"MACDUFF"
"LENNOX"
"ROSS"
"MENTEITH"
"ANGUS"
"CAITHNESS"
"FLEANCE, son to Banquo."
"SIWARD, Earl of Northumberland, general of the English forces."
"YOUNG SIWARD, his son."
"SEYTON, an officer attending on Macbeth."
"Boy, son to Macduff. "
"An English Doctor. "
"A Scotch Doctor. "
"A Soldier."
"A Porter."
"An Old Man."
"LADY MACBETH"
"LADY MACDUFF"
"Gentlewoman attending on Lady Macbeth. "
"HECATE"
"Three Witches."
"Apparitions."
"Lords, Gentlemen, Officers, Soldiers, Murderers, Attendants, and Messengers. "
Please be sure you're using Nokogiri::XML instead of Nokogiri::HTML

How do I correctly format YAML to upload objects into my DB using frozen_record gem in Rails

I'm trying to load some questions into my Question model using Frozen Record and a YAML file. For some reason the formatting is off, and I can't work out what I'm doing wrong. The intention is that FrozenRecord will upload my /config/initializers/questions.yml file and create three new Question records, with the parameters below:
The Question Model:
class Question < FrozenRecord::Base
include ActiveModel::Validations
validates :next_question_id_yes, :question_text, :answer_type, presence: true
self.base_path = 'config/initializers/'
end
The Questions.yml file:
questions:
- id: 1
question_text: Why does this company need to buy your products or services?
answer_type: Text Field
next_question_id_yes: 2
next_question_id_no: ~
- id: 2
question_text: When do they need to have completed the project?
answer_type: Datetime
next_question_id_yes: 3
next_question_id_no: ~
- id: 3
question_text: What happens if they miss this deadline?
answer_type: Text Field
next_question_id_yes: 4
next_question_id_no: ~
I get the following error:
Psych::SyntaxError: (config/initializers/questions.yml): mapping values are not allowed in this context at line 3 column 18
So presumably something is wrong on line 3, but I have no idea what it might be. I've tried adding "" around the string, but that didn't help. I can't seem to find anything that tells me how to format an entire object as YAML and upload to the DB (only results about using to_yaml methods to pull objects out as YAML).
Can anyone help please?
There is proper format of the YAML file:
- id: 1
question_text: Why does this company need to buy your products or services?
answer_type: Text Field
next_question_id_yes: 2
next_question_id_no: ~
- id: 2
question_text: When do they need to have completed the project?
answer_type: Datetime
next_question_id_yes: 3
next_question_id_no: ~
- id: 3
question_text: What happens if they miss this deadline?
answer_type: Text Field
next_question_id_yes: 4
next_question_id_no: ~

rails translation missing error

I have set flash message in my controller like this
flash[:error] = t 'auth.login.empty'
My en.yml file has
en:
auth:
login:
success: "Successfully logged in"
empty: "Empty field cannot accespted"
error: "Username and password doesn't match"
All are two space indent
I am getting flash as translation missing: en.auth.login.empty
Whether i have to make some configuration changes.
I just ran into this.
A key I was setting at the top of my file was being over-written later on in the file:
# This was showing up as missing
invite:
intent_msg: "Test intent message."
# because waaaay farther down the file I had the following:
invite:
button_text: "<i class='fi-mail'></i> Send Invite"
Even though the two translations are for different keys, the second one was killing off the first one.
So now I have this:
invite:
intent_msg: "Test intent message."
button_text: "<i class='fi-mail'></i> Send Invite"
And all is well again.
Watch out for that one folks.
Your code was actually indented with tabs for the success, empty and error keys. I have fixed this up now.
Please ensure that you are really using spaces. There's no other reason that I know of as to why this would break.

Is there any limitation on YAML indentation level?

I am developing a Ruby on Rails application with I18n support. I created a YAML file. But Rails report there is syntax error in the YAML file.
I found that if I decrease the level of indentation for that error line, no error message come out again.
Is there any limitation on YAML indentation level (in Ruby on Rails)?
Here is YAML block. The line fulltime: "Full Time" was reported has syntax error.
en:
jobs:
new:
positiontitle: "Position Title"
country: "Country"
city: "City"
employmenttype: "Employment Type"
fulltime: "Full Time"
parttime: "Part Time"
Thanks everyone. :)
there's no limitation. possible cause of error is using a TAB characters instead of spaces when indenting YAML file lines
also your yaml file indentation is meaningless - if you want to indent fulltime & parttime - then you have to remove "Employment Type" string, so:
en:
jobs:
new:
positiontitle: "Position Title"
country: "Country"
city: "City"
employmenttype:
fulltime: "Full Time"
parttime: "Part Time"

Resources