Set language of DateTime in symfony2 - symfony-forms

Is there a way to have Symfony2 translate the months within a Form?
Now I have a select with the month`s shortcut in english, I would like to have it in spanish.

This is a bit old but this may help others stumbling on this post.
I think this is not related to Symfony2 itself, but what you may want to do is set the correct locale in PHP.
See this post : https://stackoverflow.com/a/4976419
If you have the Spanish locale on your system, setLocale will do the trick.
Beware, though, that date() is not locale-aware. As seen in the post above, you should use strftime() instead.

Related

Internationalization and localization in Rails.

I am trying to wrap my head around what localization means here. I've been reading these docs:
Internationalization is a complex problem. Natural languages differ in
so many ways (e.g. in pluralization rules) that it is hard to provide
tools for solving all problems at once. For that reason the Rails I18n
API focuses on:
providing support for English and similar languages out of the box
making it easy to customize and extend everything for other languages
As part of this solution, every static string in the Rails framework -
e.g. Active Record validation messages, time and date formats - has
been internationalized, so localization of a Rails application means
"over-riding" these defaults.
What does that mean? What does localization mean here?
I think this makes sense:
The default en.yml locale in this directory contains a sample pair of
translation strings:
en: hello: "Hello world" This means, that in the :en locale, the key
hello will map to the Hello world string. Every string inside Rails is
internationalized in this way, see for instance Active Model
validation messages in the activemodel/lib/active_model/locale/en.yml
file or time and date formats in the
activesupport/lib/active_support/locale/en.yml file. You can use YAML
or standard Ruby Hashes to store translations in the default (Simple)
backend.
The I18n library will use English as a default locale, i.e. if you
don't set a different locale, :en will be used for looking up
translations.
In the bolded statement,
validations have been "internationalized" (read: supports customization for localisation)
so localization of a Rails applica.... (read: the activity of localising your application is by means of overriding the default values provided by the built in internationalization functionality.)
Will revise my answer if it doesn't help.

How to localize existing content in Rails 3?

I have set up a simple Rails app based on Post, Comment example from the default documentation. -> http://edgeguides.rubyonrails.org/getting_started.html
What would be the appropriate way of localizing existing content from these Posts ?
If I assume that Post has a :title and "content, and I would like this content to be entered not only in English, but also in German and Dutch, then how would I achieve this if I want the end result to look similar to this :
http://0.0.0.0:3000/en/posts.json to get all posts in English and respectively,
http://0.0.0.0:3000/de/posts.json for German?
I havent found a gem yet, that would support such multilangual content.
I have seen doe, many existing ways to do so, mostly in applications like Wordpress or Drupal, which are not rails based.
I guess the preferred way would be either storing EN and DE posts in seperate tables (but then how to add new languages?), or to place all translations within the same database table, but seperate translations in a different way, but how to get them easily out in json in the right language?
I am really confused and puzzled why such a "common" problem, is not solved in Rails by default, or maybe I am simply looking in the wrong place.
Globalize3 will do what you want to do. It stores all translations for a particular model in a separate table, with a locale column identifying what the language of a particular translation is. This makes it possible to add new languages without having to migrate the database, so the approach is very scalable.
There are other gems for translating content as well, e.g. Traco is one that I know of, but this one stores the translations in the same table as the model, so when you add new languages you have to migrate each model table. I personally prefer the Globalize3 approach, although it makes the gem itself more complicated internally.

Apply I18 to Ruby on Rails Completed Site.

I am new to Internationalization(I18). I want to apply I18 to my Ruby on Rails site but the problem is site is already complete and I don't want to go to each HTML page change the code. I want my site in English, French, and Spanish language.
Please show me the way and I appreciate any example or tutorial for I18.
Thanks.
Unless the development team on your inherited site had future-I18n on their mind when they made the site (e.g. strings are not hardcoded but reference values found in config/locales/en.yml using the I18n.translate method), then you will have no choice but to go in and change every file that uses strings you want to translate.
I'm sure you've already found the following references, but just in case, you should probably start with these:
Rails I18n guide
Rails I18n Railscast
Rails I18n backends Railscasts
Other Rails I18n questions on StackOverflow
As #Dougui pointed out, you probably have a fair amount of work ahead of you.
Sorry but I think there is no way to do this. It's just a very long work... Good luck!

Implementing globalization in Rails

While I have experience developing Rails apps in English, I am a blank slate when it comes to handling globalization, so please don't shoot me in the head if my question 'doesn't make sense' :)
I have been asked to add multi language feature to a part of a Rails app that I am working on. Initially its only going to be 2 languages, French and German. The content that will be translated (which is in English now) is rendered using partials at the moment hence I am getting a bit inclined on creating partials with different languages and then based on the users language selection call the relevant partial - Would you recommend this approach?
Although it seems a heavy weight solution for this particular purpose, but I am also looking at the Rails Globalize plugin. This seems to appeal if I look at the long term gains, something like what if later I am asked to translate the entire app.
Any insights on what would be a proper structured approach to handle globalization in Rails?
Many Thanks
Have you had a look at the i18n (internationalization) API that is in Rails itself as of 2.2? It makes it easy to store your language translation files as .yml files, so a fr.yml and a de.yml or whatever. It also steps through different approaches of making languages accessible via browser prefs, or URLs, subdomains, etc. In your HTML template files you use symbols to specify the keys for the string you've translated. At least in my basic usage and testing, it was very easy to work with.
I preffer using translator instead of Rail's i18n, since the former handles "scoping of translation" automatically. I recommend you give it a look.
This is a great article on how to use Ruby's GetText to localise you Rails App.

Generating urls dynamically in Ruby on Rails that may or maynot contain / in between

I am making a RoR site that is delivered in several languages, and want to change a part of the url by its language.
ex.
http://xxxx/en/index.html
http://xxxx/fr/index.html
I know I can do this via the route.rb
map.locale ':lang/index.html'
and designate the language when calling this in view. However, there is an exception
to this, when in the default language of the site, I want the url to be without the language identifier,
http://xxxx/index.html
as so.
Currently I cannot find a way to git rid of the / after the language identifier,
http://xxxx//index.html
is there a better way to do this?
It's not (yet) possible.
But you'll find some solution on this stackoverflow question.

Resources