Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localizable strings #12

Open
SamHurne opened this issue Sep 19, 2015 · 0 comments
Open

Localizable strings #12

SamHurne opened this issue Sep 19, 2015 · 0 comments

Comments

@SamHurne
Copy link
Collaborator

[Moved from Codeplex: https://gw2dotnet.codeplex.com/workitem/1239]

Right now, it is still possible to pass in a CultureInfo object per request. I'm thinking about switching to Thread.CurrentUICulture for /v2 services. You'd still be able to pass your own CultureInfo object into the constructor. When you don't, the current UI culture will be used instead.

Info: http://msdn.microsoft.com/en-us/library/system.threading.thread.currentuiculture(v=vs.100).aspx

Ruhrpottpatriot wrote Sep 22, 2014 at 4:31 AM

Yup, do it. Seems like a good default.

StevenLiekens wrote Oct 19, 2014 at 6:02 AM

I settled on a slightly different approach. I did not like the ability to change the language once a service object has been created. If a user wants to retrieve details in 4 languages, then the user should create 4 different instances of the endpoint class.

In the end, I decided on factory classes that configure endpoints for a given language. The endpoint object itself is immutable, so the language cannot be changed afterwards.

Example: ItemFactory for /v2/items

This factory class has an indexed property that expects a two-letter language code. It uses that index value to configure the item service object.

public IRepository this[string language]
{ 
   get
   {
      return new ItemService(this.ServiceClient) { Culture = new CultureInfo(language) };
   }
} 

The code wouldn't be complete without a default option though.

public IRepository Default
{ 
   get { return new ItemService(this.ServiceClient); }
} 

Usage

// Explicit language
var itemsDE = GW2.V2.Items["de"];
var itemsEN = GW2.V2.Items["en"];
var itemsES = GW2.V2.Items["es"];
var itemsFR = GW2.V2.Items["fr"];

// Default language (API decides what language to use)
var items = GW2.V2.Items.Default; 

System language
So what about automatically determining the preferred language? I was thinking about adding helpers to the factory class.

public IRepository ForCurrentCulture
{
   get { return this[CultureInfo.CurrentCulture.TwoLetterISOLanguageName]; }
}

public IRepository ForCurrentUICulture
{
   get { return this[CultureInfo.CurrentUICulture.TwoLetterISOLanguageName]; }
}

Usage

// Current system language
var items = GW2.V2.Items.ForCurrentCulture; 

// Current UI language
var itemsUI = GW2.V2.Items.ForCurrentUICulture;

Any thoughts on this? I really need all the feedback I can get on what goes into the public API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants