In my current project, on the main page I can switch language (FR|NL|UK).
All the texts are in ressources (.resx) files. The language code (FR, NL, UK) I need to use is in myMode.
How can I do to set all the : #HTML.Label( ....)
Thanks,
When you change language you need to change the current UI culture. You also need to track the user language preferences somewhere (route, cookie, session, ...). Here's a nice guide that I would recommend you reading.
I agree with the previous answer, that you have to change the current UI culture. On drop down change, you can store the language in cookie. And then using this cookie you can set the current UI culture. Depending on the culture, the application will pick up text from resource files depending on language selection.
Related
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.
Hi I want to create an application for the iPhone/ iPad, and on the initial page I want the user to have the option to change the language of the application (default language is English). Depending on the language the user chooses, for example Spanish, the initial page text and buttons will all be in Spanish. Then, after a button is pressed, the next view is also in Spanish. (And the back button is also in Spanish)
How could I do this? Remember, I DO NOT want to use Localization. Instead, I want the user to have to possibility to change the language of the app, WITHIN the same app, and NOT the Settings app.
Help with maybe a few examples would be very much appreciated.
Thank you very much in advance!
I've done this a few times. iOS is not designed for this and the first thing you should do is reconsider your approach or go back to the client and make absolutely sure it is necessary. There are only a few situations where this approach is the right one, it's mostly a mistake.
Your first issue is with localising string resources. NSBundle offers methods to load localised strings. Have a singleton class to manage which language you've currently got selected. When you change the language, it can load the en.lproj directory (or whichever language is selected) as a bundle. From that point, instead of using the usual macros to get localised string resources, use a method on your singleton to fetch them from the current bundle.
The same applies to images and other resources - your singleton knows which localisation bundle is in play, so ask it for the resources you need.
When you change language, tell your singleton, and your singleton can load the relevant bundle and post a notification so that your view controllers know to update themselves.
If you are lucky, your nibs layouts work independently of language without modification. This means you can set up a base view controller that others inherit from that has an outlet collection for localised interface elements. It should listen for the notification and walk the collection to update the necessary items.
If you are unlucky and different localisations need different layouts, you'll probably have to save state, get the relevant nib from your singleton, then reload everything and restore state.
You also have a problem that can't be entirely fixed - iOS will still think it's in the main system language. Where there is iOS-supplied content that is out of your control, it will be localised to the main system language. You can mitigate that a little by setting the user preference AppleLanguages to an array with a string containing the locale before the application is fully initialised (i.e. in main.c). However this can only change languages when the application is launched.
A possible implementation:
Use CoreData to create a table of localized strings
Store a Name/Key, language, and value.
You'll then want to build out a manager class to help you read the values. Using a singleton here would probably be a good approach. You could then do things like this:
[[LanguageManager] instance] getLocalizedString:#"mainView_title" forLang:#"en"];
Have you tried to checkout this article?
I see you are asking to NOT to use localization, but the only reason I figured out is because you'd like to change language at runtime.
That post then offers (and explains how to use) a custom utility class to meet your requirements leveraging part of the already existing localization functionalities of the SDK.
Hope that's going to be useful.
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?
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.
Ok, I'm a newbie to ASP.NET web apps... and web apps in general. I'm just doing a bit of a play app for an internal tool at work.
given this tutorial...
http://www.asp.net/learn/mvc-videos/video-395.aspx
The example basically has a global tasklist.
So if I wanted to do the same thing, but now I want to maintain tasks for projects. So I now select a project and I get the task list for that project. How do I keep the context of what project I have selected as I interact with the tasks? Do I encode it into the link somehow? or do you keep it in some kind of session data? or some other way?
As it sounds like you are having multiple projects with a number of tasks each, it would be best practise to let the project be set in the URL. This would require a route such as "/projects/{project}/tasks". It follows the RESTful URL principle (i.e. the URL describes the content).
Using session state will not work if a user possibly have different projects open in multiple browser windows. Let's say I am logging into your system and a selecting two projects opening in two tabs. First the session is set to the project of the first opened tab, but as soon the second tab has loaded, the session will be overwritten to this project. If I then do anything in the first tab, it will be recorded for the second project.
I use:
Session state for state that should last for multiple requests, e.g. when using wizards. I'd be careful not to put too much data here though as it can lead to scalability problems.
TempData for scenarios where you only want the state to be available for the next request (e.g. when you are redirecting to another action and you want that action to have access to the state, but you don't want it to hang around after that)
Hidden form fields [input type="hidden"] for state that pertains to the form data and that I want the the controller to know about, but I don't want that data displayed. Also can be used to push state to the client so as not to overburden server resources.
ok, From what I can tell, the best option seems to be to save it into the Session data
RESTful URLs, hidden fields, and session cookies are your friends.