I would like to split the messages.properties into several files, for example one will contain the validation messages, while the other the text for the FAQ or ToS.
I've been searching and I found this website: http://mrhaki.blogspot.com.es/2011/03/grails-goodness-splitting-i18n-message.html
But it didn't work.
It's possible to accomplish this, or I'm just losing my time?
Thanks in advanced.
Edit: I'm using Grails 2.3.0
In the i18n folder, I've created customValidation.properties and view.properties. Works fine for me. You have to adhere to the conventions which is keep them in the i18n folder and you can't have underscores in the names except to denote locale.
#Gregg, thank you for hint.
By the way, to keep good structure in project, you can also nest i18n files in subdirectories, like this:
grails-app
|--i18n
|--|--en_US
|--|--|--messagesUserProfile_en_US.properties
|--|--|--messagesRegistration_en_US.properties
|--|--|--messagesCommon_en_US.properties
|--|--pl_PL
|--|--|--messagesUserProfile_pl_PL.properties
|--|--|--messagesRegistration_pl_PL.properties
|--|--|--messagesCommon_pl_PL.properties
Related
My Grails (2.4.2) app was created with a bunch of "default/standard" resource bundles:
myapp/
grails-app/
i18n/
messages.properties
messages_fr.properties
I would now like to create my own "custom" resource bundle, that is, define properties in a file outside of these standard messages*.properties files that myapp was created with.
According to the i18n documentation, all bundles need to be prefixed with messages and suffixed .properties. So I added two new props files, one for English and one for French:
myapp/
grails-app/
i18n/
messages.properties
messages_fr.properties
messages_myapp.properties
messages_myapp_fr.properties
For one, I'm not 100% sure I'm interpreting the docs correctly. So if anything about my 2 new props files jumps out at you as being incorrect, please start by letting me know!
Having said that, in all the example from those docs, I don't see where you specify the bundle to use. All of the examples look like this:
<g:message code="fizz.buzz.foo" />
But what if I have a fizz.buzz.foo property defined in both messages_blah.properties and messages_bar.properties?
So I ask: How do I add my own custom resource bundles, and how do I properly refer to them from inside a GSP?
To answer your question you have to understand what Grails (well, Spring really) is doing to accomplish this.
You are on the right path with the multiple files. What you have outlined there matches the documentation and will work.
However, under the covers what is really being done is they are being combined into a single bundle (per language). So there is no need to tell Grails/Spring which bundle to use.
Finally, what happens when the same key is defined multiple times? The first one matched wins. I seem to recall that the order in which the bundles are combined is in file name order, though you should be able to test this pretty quickly.
Hope this helps, and best of luck!
I have one Rails application and all files are in erb format. Is there any quick way to convert whole application's erb file to haml.. without any conflict.
And also would like to know for the Reverse..
Thanks in advance. :)
For erb-to-haml
You can use from the command line html2haml
html2haml your_erb_file new_haml_file
If you want to convert all your files in one go, look at this article : http://shifteleven.com/articles/2008/06/08/converting-erb-to-haml-snippet
erb2haml gem will do the trick.. have a look to https://github.com/dhl/erb2haml
For haml-to-erb
I recommend you HAML2ERB service . It's really cool and generates valid ERB/HTML code! Tested on big HAML views (over 800 lines of markup) from the real production app. Project active :)
have a look to this also http://makandracards.com/makandra/544-convert-haml-to-erb
I am using tolk for translation, but tolk takes all my values from en.yml and dumpes them in es.yml overwriting the existing content .
There are some stuff i don't want to be overwritten , so when i am searching for the es translations, i want rails to look in both es.yml and es.defaults.yml
( and so, i can keep isolated what i generate with tolk, and what remais the same )
Is there a way i can do this?
Thanks
Rails loads every file in the config/locales/ directory, so it will probably already work like you're suggesting. You can even organize it further than that, according to the I18n Guide:
http://guides.rubyonrails.org/i18n.html#organization-of-locale-files
However, I think that with duplicate key structures, Rails will probably override the values of the earlier loaded (sorted by file name) locale file with the values of the later loaded file. So please try to avoid duplicate keys.
I want Rview to jump to .js.erb-views as well.
It always says "Can't find file "app/views/examples/foo".
The help says:
rails-template-types
Commands like :Rview use a hardwired list of
extensions (erb, rjs, etc.) when searching for files. In order to
facilitate working with non-standard template types, several popular
extensions are featured in this list, including haml, liquid, and mab
(markaby). These extensions will disappear once a related
configuration option is added to rails.vim.
Since the view ends with .erb, i would suggest it should work.
Any Ideas?
This is strange, I just checked in my vim and it works fine. I use Janus, but I think that the standard vim + rails.vim should work well.
Maybe you need to update rails.vim?
And you can tell the sequence of your actions: the current file, typed commands, etc.
Is there any way to to setup Rails generating files with tabs instead spaces?
Or maybe is there any way to auto replacing spaces to tabs in gedit?
Cause I really prefered tabs and it's really take some time to replace spaces to tabs in new generated files by Rails.
Thanks in advance!
To do this in gedit, try the Tab Converter plugin.
(Don't think there's a way to do it directly in Rails.)
Unfortunately there isn't a simple way. The generators begin copying a template file into your project and then substitute the various variable names into that template.
The template files that are copied into your project use spaces, so you'd need to monkey patch some filter into the generators; a filter that would regex replace the leading spaces with tabs. Not an ideal solution.