I am at the end off my project. I implemented few languages.
But this moment, I have categories that are placed in database, but these categories are in my native Latvian language, what would be the trick to be able change language of these records simultaneously with display language change.
It means that If I choose locale en, then these category names are displayed in english.
Some ideas!
To store ultiple language translation within the records, I think it's bad idea.
Or to store just put latvian category name as id inside <%= I18n.t 'category_id_in_latvian'%>
and just in yml files put the translation ?
Or there are other solution?
Thanks
You should take a look at the Globalize Gem:
Github of globalize3 Gem
This gem should do exactly what you need. ;)
And if it doesn't, please, explain why by providing more details on what you want to do and I'll update my answer according to your needs.
Related
I have the following problem, I'm using the standard i18n to translate to spanish all the website (:es), but now I want to change model label that depends on regions and not only language.
So I want to use es-MX,es-AR,es-PA and so on but in the documentation it says that rails doesn't support regionalization.
Some examples of regionalization:
For some model labels I use: DNI (identity document) but in mexico the correct label is IFE.
So is there a way to add support for es-MX, es-AR and other regionalizations
If you look here https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale then you will see that the regions you want are present here as separate languages. You can do what you want the same way. Just use each region as a separate language. Good luck !
I waste tons of time trying to construct the the proper yaml for translating text and labels in Rails.
Is there an easy way to pinpoint what path I should use in the YAML to provide the translation?
As an example, I am using a nested simple_form with this form erb:
<%= f.input :birth_date, as:'string' %>
The label I get is Birth date and I am assuming is just coming from the model attribute.
When I debug that line and type f.object_name I get
=> "user_wizard[children_attributes]
Here's my YAML
en-US:
simple_form:
labels:
user_wizard:
children_attributes:
birth_date: "Name Date or Expected Date"
Is there a sure-fire way to log, print, probe, watch, render or query that will give the (or one) exact path I need in almost any situation? Not just simple_form or a model attribute but for error messages, buttons, mailers, etc.
We have had tons of issues with the i18n key management as well, that's why we have decided to go down a different road and display the whole key name, with a possibility to edit it in place as well. We feel that this solves the problem of finding the correct key name and filling it. Check out our solution, PhraseApp and especially our In-Context Editor.
To summarize: The best thing might be to expose the key name through code. We have built our own solution, but you probably can do it with a little monkey patch to i18n as well.
I'm trying to expose a search feature in rails. I want a user to be able to enter a string like name:"john" color:"blue" and get a list of ActiveRecord objects for some model that have a name attribute containing john and a color attribute containing blue. I'd also like them to be able to use and and or and parentheses e.g. name:"john" or color:"blue" or (name:"john" color:"blue") or name:"bill". Ideally they could also use things like age<20 where age is an numeric field. Is there a rails plugin that does this. I've was looking briefly at sphinx and ferret both of which seem to create an api for this but it was unclear whether they provided a clear text based option or if I would need to parse the search strings myself.
Ernie's Ransack gem is a good place to start.
You will have to provide an intermediate layer between your submitted form and the Ransack code (this would be a good idea anyway for security reasons) to convert strings from the format you desire to something Ransack can understand.
If you check the demo page and the documentation for the gem you'll find it's quite simple to create the sort of queries you're after.
Watch how GET requests are generated from the conditions you build and in your application replace the builder Ernie has in the demo with a single textfield accepting strings like (name:"john" color:"blue") or name:"bill". Do some pattern matching when this field is submitted and build a proper querystring to pass onto the Ransack gem.
Edit
For future questions like "what's a popular gem for ______?", check out The Ruby Toolbox. If Ransack doesn't suit your needs, perhaps a gem in the Rails Search category has what you're looking for. I personally use Ransack for exactly what you're describing; providing a custom query interface for my application's User model.
I'd suggest doing your own search class. I find that for each app I do, the needs of search change considerably and it's simple enough to create a search app that considers all the variables you might want in a search query, posed against any number of classes you want to search.
In your Search class, have it return a collection, in the order you desire, and the collection can be made up of object instances that the searcher may desire.
Let say i have a basic tagging system (for a craiglists "clone") such as:
Tag (id, tagname)
ad(id, title, body)
adTag(tag_id, article_id)
This will fit for a non-localized website but what will be the correct aproach for a website that is used by people speaking diferent languages?
Users probably will post ads in diferent languages in one same local area, so, maybe i should make some kind of synonym system that considers "job" and "trabajo" the same tag? But, what about users that only want to see ads in one language?
Catering for tags for all the different languages is probably just going to be trouble. Going with the idea where you treat all variations of a tag as one single type will probably simplify a lot of the issues (so you don't need to keep track of language-tag mappings on the fly, just do the conversion once and be done with it). If the user needs to search by language later on, then just stick a meta-tag for that particular language on when you save the post.
Of course, that leaves the question of what happens when a user uses tags from multiple languages... but I suppose you can always enforce one single language or something.
I can think of two possible solutions:
Add language field: Tag (id, tagname, lang) where you can specify the language for the tag
Change Tag to Tag(id) and use separate table for tag translations tagTranslations(tag_id, lang, tagname)
Note: But I think this is only needed, if your articles have multiple translations.
I want to have Greek support in my rails app for the messages/flashes etc. I took a quick look at the I18n framework but it seems like a lot of configuration for something so simple. I thing that there should be a very easy way to do something like this but ( apparently ) I don't know it. If anyone would be willing to help me I'll be glad. Thanks.
Rails has conventions so you don't have to configure.
Create a file in config/locales/el.yml with the contents:
el:
flash_messages:
success: "επιτυχία"
fail: "αποτυγχάνουν"
Then in your controller:
flash[:notice] = t('flash_messages.success')
and you'll get the translated string in your view.
You can change the locale like this:
I18n.locale = :el
I don't know how it could be easier. The "Rails I18n Guide":http://guides.rubyonrails.org/i18n.html has all the gory details if you want to fight the conventions or go beyond simple.
I18N ain't simple.
Here are some of the reasons why internationalization is hard.
First, every piece of text that might be shown to the user is a potential candidate for translation. That means not just properties of components (like menu items and button labels), but also text drawn with stroke drawing calls, and text embedded in pixel images (like this one taken from the MIT EECS web page). Translation can easily change the size or aspect ratio of the text; German labels tend to be much longer than English ones, for example.
Error messages also need to be translated, of course — which is another reason not to expose internal system names in error messages. An English-reading user might be able to figure out what FileNotFoundException means, but it won’t internationalize well.
Don't know Ruby so I can't help you more.