• Define scoped resources in a modular solution by specifying the global, the application and/or custom ones.
• Dynamic loading, so you won't need to download all resources available, this will be done on demand.
• Observable resources, so if you change the culture, automatically all labels will be updated. No code is required.
• Shared resources, in modular solutions, you can have a solution with some projects, another solution with some other projects and so on. With this, you will be able to add it sharing the resources.
• Enable for unit testing.
Solution explanation
This functionality is an extension with many changes of: http://www.wintellect.com/CS/blogs/jprosise/archive/2010/06/21/dynamic-localization-in-silverlight.aspx
• LocalizationManager will be the manager for changing the culture, downloading the requested resources for all cultures.
• Modules may call to LocalizationManager in order to retrieve the Global, Application and other custom scopes.
• What returns the LocalizationManager is an observable entity, that in XAML, it can be called like a normal entity.
How to do
To create a new scope
• In your main project, you need to create your neutral resource into a Resource folder and name "Resources.resx".
• Then create all projects for each language that you need to give support. For each project, you need to create the resource file for its proper language into a Resources folder and check that the Build Type property of the created resource file is set to Embedded resource.
• All projects for the languages must have set in the default namespace the same than the main project one.
• In the main project, you must initialize (for global and local) or add (for custom scopes) the created scope.
To retrieve resources within a scope
• Just calling a static property of the LocalizationManager you will retrieve the ObservableResource for the global and local resource (For custom scope, there is a proper method to retrieve it.)
• To access to the keys of the resources, you only will use the instance returned in the previous step like a normal instance.
More technical details
• LocalizationManager has static methods of type <T> to instantiate the resources.
• ObservableResource contains the resource for a specific scope by using the boxing/unboxing technique, this is because the ObservableResource entity is a generic one that can't have the reference of the target project.
Other alternatives
• Contain the resources into the server project host but you will be able to have neither a separated solution nor scoped resources. (This mechanism is used in WCF Ria Services)
If someone is interested to view the solution, just send me an email with the request.
2 comentarios:
your solution is exactly what I am looking for. Would it be possible to view the solution?
Hi, i am also looking forward for the solution.Could you please mail it to tittiskaria@gmail.com
Publicar un comentario