Global i18n for social app in Rails - ruby-on-rails

I'm creating a social app that may have different languages. I don't want to follow the pattern described in the Rails manual that makes use of different URL parameters for different languages. For example:
http://example.com/pt/books
I want to set things like this:
When an user enters the site (not registered), the locale is automatically defined by the browser language profile. (Probably the current locale will be saved in a cookie). If there isn't a language that matches the browser language then the default will be english.
When the user fills the registration form, the current language provided by the browser will be saved in the database in the users table, so even if the browser's default language is different from the logged user's default language, the last will be the main language. This time the locale won't be saved in the cookies.
The LOGGED user will have the option to change the language in a configuration page. This will affect the database entry.
The VISITOR user will have the option to change the language in the home page. This will affect the cookie. There will be probably a route to change this option, like:
http://example.com/changelanguage/en
So, what's the best and simpler way to create something like this?

Check out the locale_setter gem, it should do exactly what you're after.

Related

One URL which will direct customer to the correct store (based on location and language)

We have a multi-store setup with more than 10 stores (different languages and domains), which share many products between them.
The problem:
If we want to do a product promotion on say - Instagram, and include a product URL in the description, it would only be one store (obviously, its dumb to direct a Spanish customer to a Danish site), so:
How to create a "universal" URL which will automatically redirect the customer to the correct store (based on location and language).
Note: Our sites do have hreflang with alternate hrefs set up.
EDIT
Our store is based on Magento framework. My current idea:
1)Have a URL with a parameter of a product ID.
2)This URL directs to a PHP file in which I receive the parameter, by which I can get the product data, then I can loop through the available alternate hrefs (from database).
3)I get the user locale and language (Im not very sure how to do this).
4)Check if any of the available hreflang matches this user and direct them to it.
As you synthesised in your update:
Have an URL with a product ID parameter
In a PHP file, receive the parameter, and retrieve all available languages from the database for that ID
use the Accept-Language header to see which of the languages is the best fit for the user. Pick English if none match, because default world language, yada yada. Using the PHP HTTP_ACCEPT_LANGUAGE server variable has several implementations of a function that does this.
Serve a page with 302 Found status, and Location header that points to the localised URL. It may be good to also include the body with all the metadata (I'm not expert in SEO, and not 100% sure what Google will or won't look at and/or remember when it encounters a 302).

Results returned from Prestashop do not match given values in plist...expected behaviour?

I have created a mobile app using appixia for an existing site...our existing site has existing users, who have put their existing addresses into our database (prestashop/mysql).
One of these fields (Address Line 2) has been used for the UK County (similar to US States). As this was free text entry, users have used abbreviations etc in this field.
My mobile app I have generated, I want to use a plist for the users to select their county. This would work well for new users.
For existing users logging in, when prestashop returns their "county", and it DOESNT match a given value in the plist, what is the expected behaviour? This is difficult for me to simulate, but I would expect it to leave the field blank if no value sent from prestashop matches a plist value?
Just to make sure I understood correctly, you are building your plist according to this example, and in the Value fields you don't use a numerical value (like the example) but instead put the text of the county name. Since the Prestashop Address Line 2 is free-text, this works out and fills-in the name that you put in the Value.
If there isn't a full match to the user's current address, the expected behavior is either to leave this field empty or use the first selection value from the list. Not sure which is it, I suggest you test it out :) It's shouldn't be that hard to simulate, create a user in Prestashop through the website or the website backoffice and set a random value to Address Line 2. Then login using this user in the app. Another idea is to create a user in the app, and then using the website backoffice edit his address and change Address Line 2 to some random value, and then login once again through the app.
In any case, between login and re-login, it's best to restart your app (or the Visualizer), to make sure cookies are deleted and you're logged out.

Changing language by domain (localization/globalization)

I have a webforms website that needs to be set either to danish (DK) or swedish (SE) language depending on the domain (.se/.dk). Theres both some global and local resources. Mostly local. The language needs to be set once, global for the entire application, once the clients lands on the page (session start).
The auto settings in web.config will not be sufficient, cause some of the users will have english settings on their browsers, launching the default resources (which is danish). Not optimal if youre a swedish user with english settings.
If i run an overrided method of InitializeCulture() on for example default.aspx and ask for host/domain and set the langauge from that, the culture will be reset to the default resources as soon as I leave the default page. Setting the culture in Session_Start in global.asax will do the same thing. Works on landing page, resets on sub page.
Whats the right way to do this?
I guess the question comes down to: Do I really have to call InitializeCulture() on every single page?
Apparently yes - I have to call InitializeCulture on every single page:
InitializeCulture() on every single page necessary?

Best way to save localized static content

I am creating an application to have administrators enter the a localized static content of a page.
For ex. nowadays the "About Us" content is English, I would like an admin to be able to enter the same "About Us" content in Russian.
How should I store the localized content?
I'm thinking that the admin won't be able to edit the YAML files for each language.
i thought storing all the data in a table and have a reference language id to it stored in a cookie.
Having a call to the locale cookie each time a view loads checking out which language I am using, comparing it to the database and then calling the specific row where language = en/ru/whatever.
any better way?
Nowadays, you can simply put index.fr.html.erb and index.en.html.erb in the same folder and rails will do the rest.
odin is right, I do mean storing multiple versions of pages in different languages,
I thought I could just leave it in YAML and in-place edit it and I stumbled across this -
http://asciicasts.com/episodes/256-i18n-backends
We change the i18n backend to Key-Value backend (Hash) but then it would mean that each restart of the webserver the hash will be lost and thus the article suggests using Redis another key-value storage which calls itself
Redis is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.
It seems fairly clever saving it like this, because I still use the Rails l18n, meaning I can route everything fairly easily, but I am enabling the user to edit the content for each locale.

Where to store selected language on multilingual site: session/cookies or url?

I have a site that has all its content translated to multiple languages and has no accounts (to set prefered language there).
I can detect preferred language using Accept-Language, ip or anything else.
I have 3 ways to store user language selection:
Detect language and store it in cookie/session and allow switching language (and also store it in cookie/session)
Use detected language if there is no language specified in url, and show links to url with different language
Use default site language and show links to other languages
Storing langage in url can be of any type: different domain, subdomain, or somewhere in url
I think about first case as it allows me to send one url to anyone and it will be presented to them in their preferred language. But another opinion is that different language means different data, so it must have different link.
Store it in the URL as part of pathinfo, preferably as close as possible to the domain name. E.g. http://example.com/en/page or http://en.example.com/page. It's not only SEO friendlier, but it is also guaranteed to work with cookie/session-less clients.
You can also choose for a combination. If the client supports cookies, you could make use of it to store the "preferred" language. If this information is absent in the session, then redirect to an URL which displays the language which matches the Accept-Language header the most and store this language in the session (which is in most programming languages/frameworks by the way already backed by a cookie). If the user changes this information, then reflect the change in the session as well.

Resources