Is there any limitation on YAML indentation level? - ruby-on-rails

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"

Related

Sublime Text & Source Tree cannot see FileDiff in files generated using xml.File and fsObject in Excel VBA

We are looking at certain .yml files that store translation of a Rails application. For example, the structure of en.yml is as follows:
en:
blog:
left_navigation:
list_topic: "Blog topics blah blah"
articles:
show:
by_author: "By %{author}"
number:
currency:
format:
separator: "."
delimiter: ","
format: "%u%n"
admin:
blog:
topics:
form:
topic_name: "Topic name"
topic_parent: "Parent topic"
save: "Save"
cancel: "Cancel"
As part of our team's translation procedure, we have translators translate changes in Excel, then reexport the new .yml file via macros. The relevant code is:
...
FilePathAndName = ExportFolder & ExportLang & ".yml"
...
Set xmlFile = fsObject.createtextfile(FilePathAndName, True, True)
maxline = TargetRange.Rows.Count
i = 1
For Each mCell In TargetRange
line = mCell.Value
xmlFile.write line & IIf(i = TargetRange.Rows.Count, vbNullString, vbCrLf)
i = i + 1
Next mCell
xmlFile.Close
...
However, SublimeText cannot see FileDiff when looking at both files together under "Open Folder" interface. Similar, when loaded to Source Tree it says that the 2 files are not identical, but it fails to show the file difference.
We need this file difference to verify that the translations were done with correct syntax. Could somebody help us?
Thanks for your ideas #Odatnurd and #barrowc
The issue comes from the encoding of the second (destination file). Apparently it needed to be UTF-8. So I just resaved this file in Sublime Text with Encoding = UTF-8 and FileDiff worked again.
So a final question is, how do I make xml.File and fsObject in Excel VBA save the file in UTF-8 format?

Rails: = provide(:title, t('.title')) fails if there is a single quote

I can't figure out how to fix a problem with a title translation that contains a single quote. More of that it happens only when calling
= provide(:title, t('.title'))
When referencing the same YAML translation as H2, it is displayed correctly:
.row
h2 = t('.title')
Here is a line of YAML translation line:
home:
faq:
title: FAQ
about:
title: "À propos d\'Entreprise"
The title is displayed as follows
À propos d'Entreprise
Any idea about how to solve that ? Thank you.
OS: OS X
Rails 4.2.5
Ruby 2.3.0
YAML
Found out how to fix that. I think it is due to the way that Slim interprets code snippets
So here is what I had in application.tml.slim:
title =full_title(yield(:title))
The working version is:
title ==full_title(yield(:title))
Hope this helps.

Rails 4 - Seed images from hard drive with carrierwave

I'm trying to seed images with carrierwave. After looking at some questions, including this one, I have tried:
c1 = Category.create(
name: "About Us",
page_title: "12 Years of Tradition",
page_description: "long description here",
page_content: "a lot of content here",
link_to_subcategory: "Meet the Robinson's",
banner_image: open("RF_web_about_us_1.jpg"),
main_image: open("RF_web_about_us_2.jpg"),
home_page_content: "content here"
)
Unfortunately, I get the following error when I run rake db:seed
rake aborted!
Errno::ENOENT: No such file or directory - RF_web_about_us_1.jpg
The image (RF_web_about_us_1.jpg) is stored in app/assets/images. Any help at all with this would be much appreciated.
You have to specify the full path to the image:
File.open(Rails.root + "app/assets/images/RF_web_about_us_1.jpg")
Another way to do this:
Rails.root.join("app/assets/images/RF_web_about_us_1.jpg").open
So your create statement will look like:
c1 = Category.create(
name: "About Us",
page_title: "12 Years of Tradition",
page_description: "long description here",
page_content: "a lot of content here",
link_to_subcategory: "Meet the Robinson's",
banner_image: Rails.root.join("app/assets/images/RF_web_about_us_1.jpg").open,
main_image: Rails.root.join("app/assets/images/RF_web_about_us_2.jpg").open,
home_page_content: "content here"
)
Reference: https://github.com/carrierwaveuploader/carrierwave/wiki/How-to:-%22Upload%22-from-a-local-file

How to translate errors and attributes of model in 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

Middleman Localization gives 404

I'm trying to user MiddlemanApp to localize a website, following this http://middlemanapp.com/guides/localization guide.
I have a locales/ folder under the project's root, with en.yml and it.yml inside. The files looks like this:
en.yml
---
en:
rooms: "rooms"
restaurant: "restaurant"
bar: "bar"
contacts: "contacts"
gallery: "gallery"
about: "about the website"
press: "press"
it.yml
---
it:
rooms: "stanze"
restaurant: "ristorante"
bar: "bar"
contacts: "contatti"
gallery: "galleria"
about: "il sito web"
press: "stampa"
The localization files seem to be loaded, when i start the server i get:
Using inline Guardfile.
Guard is now watching at '...'
LiveReload 1.6 is waiting for a browser to connect.
== Locales: en, it
== The Middleman is standing watch on port 4567
when i navigate the the site root http://localhost:4567/ the page loads and the localization strings are taken from the it.yml localizazion. Shouldn't it go to the en.yml? According to the documentation it should take the locales in alphabetic order if not differently specified.
When i navigate to http://localhost:4567/en/index.html or http://localhost:4567/it/index.html, instead, i get a:
File Not Found
/it/index.html
I tried to restart the server, change the parameters of the localize function in config.rb (path and mount_to_root), but got nothing different. Anyone have ideas?
This will depend on the contents of your /source/localizable folder. Only templates in this folder will have access to i18n values.
If you're still having issues, please submit a bug report.

Resources