开发者

WP7 localization does not work

开发者 https://www.devze.com 2023-04-10 13:41 出处:网络
I\'m trying to do a simple localization of my app, making it support English (default) and Danish. I\'ve followed the MS tutorial, and I\'ve looked at some samples but for some reason the simulator d

I'm trying to do a simple localization of my app, making it support English (default) and Danish. I've followed the MS tutorial, and I've looked at some samples but for some reason the simulator does not show the danish version when I choose danish language as the simulator language.

Here's what I've done:

Added supported culture: dk-DK;

Changed assembly info to use "English" as default.

Added the resource to app.xaml:

<Application.Resources>
        <local:LocalizedStrings xmlns:local="clr-namespace:LåneRegnskab" x:Key=开发者_开发知识库"LocalizedStrings" />
</Application.Resources>

Added "AppResources.resx" and "AppResources.dk-DK.resx" to project with the strings.

To use the strings I write:

"{Binding Path=LocalizedResources.Title, Source={StaticResource LocalizedStrings}}" 

LocalizedStrings class:

public class LocalizedStrings
{
    public LocalizedStrings()
    {
    }
    private static AppResources localizedResources = new AppResources();
    public AppResources LocalizedResources { get { return localizedResources; } }
}

This all works for the english strings, but they do not change when I'm in danish mode. What am I missing here? :(


Nothing obvious wrong with your code. Try force-chance the culture in App.xaml.cs with the following code in the InitializePhoneApplication method.

private void InitializePhoneApplication()
{
    Thread.CurrentThread.CurrentCulture = new CultureInfo("da-DK");
    Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;

Update

Also ensure that SupportedCultures in your ProjectName.csproj file is set to support both languages, like this: <SupportedCultures>en;da-DK</SupportedCultures>


Thanks to Claus, I solved my problems (I seem to have made all the mistakes getting there) but here's all the settings that work for me. I'm supporting English and Spanish and changing the region of the emulator to see it work.

In the .csproj

<SupportedCultures>en;es;</SupportedCultures> <-- I was being too specific on language here

WP7 localization does not work

I also had AppResources-es.resx <-- Rather than .es

In my GamePage.xaml

WP7 localization does not work

I made the mistake here of having LocalisedStrings in both source and Path.

In the App.xaml I didn't add the namespace inline, but the same otherwise.

WP7 localization does not work

Hopefully it's a mistake in one of these steps as it was in my case.


I struggled with the same problem and I've just found the solution. In the csproj file the node is defined by default, but I didn't noticed that and I created another one at the first lines...

So if you remove this(or set your cultures here) it will probably work.

<SilverlightApplication>true</SilverlightApplication>
<SupportedCultures>
</SupportedCultures>
<XapOutputs>true</XapOutputs>


You have to change the csproj file as in the example bellow

http://msdn.microsoft.com/en-us/library/dd941931%28v=vs.95%29.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号