2

The title is a little misleading. I have to build a new Web API application to service a bunch of different clients that we are also building. I don't need the parameters or the routes in the API localized.

Basically the clients will ask for a resource in a specified language and the web api will return the results.

My only requirement is that the localization resources will be stored in a SQL DB and not resource files.

Being that the Web API is only returning localized results and it doesn't need to be localized, should I try to be following .NET localization practices or should I just create a simple, cached table lookup function mimicking localization routines?

1
  • Please provide more details on your requirement. do you mean translations as well? what do you mean by api returns localized results? does the database already hold different sets of localized data/results? Commented Mar 31, 2017 at 12:44

1 Answer 1

4

Technically speaking how you save the localized information at the server side doesn't matter to the client application (calling the API). You can save it in a database or you can save it in resource files; all depends on the architecture of the system.

But you can solve your requirements in two ways:

  1. Put locale in the api url: The client application can supply the appropriate locale as below:

GET https://apiserver.com/api/v1.0.0/en-GB/cities

GET https://apiserver.com/api/v1.0.0/fr-CA/cities

GET https://apiserver.com/api/v1.0.0/en-US/cities

At the server side you can configure your method as below:

[Route("v1.0.0/{locale}/cities")]
[HttpGet]
public List<City> GetCities(string locale)
{
    // Get cities by locale
    return cities;
}
  1. Pass the locale information in HTTP header. At the server side read the locale passed on in the header and send across response accordingly:

    public WebRequest GetWebRequest(Uri uri)
    {
        WebRequest request = base.GetWebRequest(uri);
        request.Headers.Add("locale", "en-GB");
        return request;
    }
    
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I've been thinking that I've been over thinking this whole localization requirement. It's not a typical case of localizing a front end.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.