I am writing a desktop application using MVVM and Prism and I have the following problem. As well as the labels etc it is also necessary to store data in different languages.
For example, in the USA a user might be able to login using either English or Spanish (as they are a native speaker).
If the user logs in using Spanish when they go into a product details
form the product description will be saved to the database against
the Spanish language.
If they log in using English the product description will be saved to
the database and related to the English language.
At the moment my only ideas is as below:-
- a globally accessible ApplicationViewModel that contains a
CurrentLoggedInUser property
What I would like to know is how I go about saving the currently logged in user's chosen language when using MVVM, particularly in a desktop application?
N.B the chosen language can be different to the language and locale that the operating system is in
How do other people go about resolving this and maintaining the user's "session" across different windows / user controls when using MVVM?
All you need to do is store the current language somewhere, maybe as an LCID.
Generally this is used to load a language specific resource file, which takes care of most language dependant situations. Controls etc just store all their strings in resources, so they don't need direct access to the current language.
For situations where you do need access to the language, such as knowing where to save your database string, then yes, the language should be exposed either as some static/singleton, or more desirably, should be injected into whatever ViewModels need it.
Related
I want my Aurelia app to support multiple languages. For example, when a user navigates to www.mysite.com/sv/start, I want them to view the site in Swedish. What is the best approach for solving this problem in Aurelia?
There is an Aurelia plugin for handling internationalization. Here are some helpful links:
GitHub page
Getting started
Aurelia localization
Using multiple translation files in aurelia-i18n
i18n update announcement
Since we share translations (web portal based on Aurelia and various mobile applications) we use this approach:
Translations are in database;
In Aurelia project we have LanguageService class responsible for loading translations from database and taking care about current language and related, language specific, culture information;
LanguageService is instantiated on the login page and then injected among components via #autoinject from aurelia-framework;
Each component or page has its own binded labels and properties translated from LanguageService;
This approach can be applied in your case because you can parse language id from given route.
I am developing one application where the client wants to see contents in both arabic and english. The displayed data is retrieving from database SQL.
The question here is If the user saves his details in database in english language, how can i show that data in arabic from database?
How can i achieve this part?
You have to use a translator API and save both the languages to database.
I don't know how you can do that without using some sort of translation service, there is nothing in .NET or SQL server (or any other RDBMS that I know of) that will do that for you.
Here's one (API) that is from Microsoft if you need a place to start: https://www.microsoft.com/en-us/translator/translatorapi.aspx
Depending on your requirements, you may want to translate data immediately and store it into the opposite database; however it may end up being expensive, so if you're able you might choose to translate things on demand to save some costs.
i think An effective way to create localized Web pages is to use resource objects for your page's text and controls. By using properties placed in resource objects, ASP.NET can select the correct property at run time according to the user's language and culture. The process is straightforward:
Resource Files and ASP.NET MVC Projects
fore more info
I am developing a mvc 5 web application which allow user to select language and currency to be displayed to them, in which the choice of language and currency they selected is expected to be retrievable throughout the controller and view.
Do note that the user i referring here is anonymous user (which is user that do not log in) so i do not intend to save their selection to database.
I am thinking of using session to store the selection. However, it seems not a good choice of to me as these are only two values that i need to store in session. Is there any other better alternative?
An alternative is to put language in url
{language}/{controller}/{action}/{id}
e.g.
en/home/index
fr/home/index
Advantage is that the url is bookmarkable and clearer
An example implementation: http://adamyan.blogspot.sg/2010/07/addition-to-aspnet-mvc-localization.html
For currency, I'll probably determine it from the culture of user, or at least use that value as default for first time user. If you want to let user be able to change it, cookie is fine in my opinion.
I am learning C# using Visual Studio and I am running into some issues.
I am developing a Windows form application. The application is meant to track user's running stats.
In settings: they select how many days they run and for each day they add their workout (ie: 1: 100m sprints 2: 50m sprints 3: Run a mile).
Then in the main windows form the user will be able to add their times and save it. Meanwhile a graph is projected of their times- this will allow the user to track their progress.
My question is where should I store their times? Right now I store all settings in the settings.settings doc. For the times should I use the settings file or a SQL database of some sort?
SqlCE or SQLite or any other simple inproc database will be better than Settings file.
Settings are not meant to grow with every user input, this is a task for a database, also it will be much easier to query your data using SQL.
Answering your question in comments:
There is a difference between user data and user preferences. You have to decide which is what in your app.
I would go with Settings file with everything regarding user preferences. Like form layout, colors, sounds, window size and so on.
Since Settings managing framework is pretty sophisticated, you will save yourself some time designing tables for user preferences and developing access to that tables.
Another possibly bright side of Settings file - it can be edited manually with text editor.
It is not possible to answer you without a lot more information about what a "user's running stats" is and how it is used. I can give a few general guidelines, though.
System.Configuration.ApplicationSettings are designed for customizing an application for a specific user; for example, what language the user wants the application to use, where he wants windows to appear, or default values. Settings are part of the application; they are created when the application is installed and deleted when the application is uninstalled. If multiple users run the application, each typically gets their own settings. You typically define settings when you create the application and users never add or remove them.
Databases are used to persist user data. They are typically not tied to a specific user or application; users add the data, which is available to other users or applications. Applications typically aren't installed with all user data, nor is user data deleted when the application is uninstalled.
SQL databases are used for relational data; data that has internal structure, like "all users must have exactly one address", or "any user may have zero or more phone numbers". If your data is not relational you do not need a relational database.
These are general guidelines, specific applications may do things differently for specific purposes. If you tell us more about your application we will be able to provide more specific information.
In My Project, there are different web pages and My requirement is when a User logs on based on user's language,page has to be displayed in user language.
I have googled it,but does not get proper solution.
I have got Satellite Asssemblies as a solution,but how to implement it?
MSDN documentation of ASP.NET localization is good place to start reading about it. Basic steps are as follows:
Localize your web pages - these would create language specific resources that will yield satellite assemblies for supported languages.
Localize other aspects within application e.g. date/time formatting and input, images, user messages etc
Set the culture and UI culture within your web pages as per needs (e.g. based on browser settings or user preference or user selection etc.). See this for how to do it.
See this walk-through that would quickly walks through basic steps.