Spring resource bundle customization - use variant with country suffix - spring

I would like to customize the way Spring retrieves resource bundles.
I have the following files:
messagess_it_IT.properties (with Italian messages)
and
messagess.properties (with English ones).
When someone has Accept-Language header set to it, I want messagess_it_IT.properties to be used.
Currently, my app falls back to messagess.properties instead.

Related

Implementing a translator service in Spring Boot

I do have a requirement to create an application that can have a language added to it without a problem. The client wants to have a totally language agnostic frontend and all the translating to be done on the backend.
So I am thinking of implementing a translator service that acts like the following:
If intercepts the request (a filter)
Extracts the header to see if
the language is not English (assuming it's the default one)
Translates each field value with values from a table with a
a structure like this:
eng_field, lang_fk, translation
Upon finishing with the processing I will reverse the process.
Is there a better approach?
If so please be kind to share it.
Thanks in advance.

Accept-language sent from browser does not change JSF validation messages locales

In the JSF app I'm working on we use message bundles and locales extensivelly. Nearly all labels are defined in a set of *.properties file, there is one file for each language, etc. This works great, whenever the user changes its language preferences on the browser and refreshes the page, those labels change accordingly.
The only labels that do not change are the 'native' JSF validation messages. Those messages are always on the language defined in the JVM during server startup (we use JBoss 7.1 and eap 6.3). So, for example, if in the startup script the this is defined: -Duser.language=en the validation messages will always be in English.
example: Validation Error: Value is required.
If, however we change the property to -Duser.language=pt the validation messages will come up in portuguese.
example: Erro de validação: Valor é necessário.
All the other labels do not have that behavior, so they do change according to the browser's language preference.
We did not specify custom validation messages anywhere.
In faces-config.xml we have the following:
<locale-config>
<default-locale>pt</default-locale>
<supported-locale>pt</supported-locale>
<supported-locale>en</supported-locale>
</locale-config>
If I understand what you're asking right, it sounds like what you're wanting is
message bundles.
A message bundle works like a resource bundle does, except they apply to warnings and errors.
I believe the following answer will help you: https://stackoverflow.com/a/2668602/4042348

REST Web API URL to update a resource property

To update the resource i have exposed following reset web api url -
http://server.com/api/v1/{companyid}/resources/{resourceid}
and request body contains the resource to be updated.
I have also exposed a seperate API to update a property of same resource. From business rule perspective this is special property and cannot be updated/retrieved along with normal resource api.
So using following url to expose separate api as below -
http://server.com/api/v1/{companyid}/resources/{resourceid}/property?propertyKey=propertyValue
this does not sound good. Is there better approach?
Answer from the comments for others
PUT api/v1/{companyid}/resources/{resourceid}/{property} with the Body containing the value of the property is one way.
PUT api/v1/{companyid}/resources/{resourceid}/{property}/{propertyvalue} is another way if you want the value entirely in the URL.
Of course, http://server.com/api/v1/{companyid}/resources/{resourceid}/property?propertyKey=propertyValue is also probably fine.
As #David-Brabant mentioned don't version your API's in the URL

Output all language strings in Revel?

I'm developing an API Server in Go and the server (at the moment) handles all translations for clients. When an API client fetches particular data it also asks for the translations that are available for the given section.
Ideally I want to have the following folder structure:
/messages
/home.en
/home.fr
/home.sv
/news.en
/news.fr
/news.sv
Where news and home are distinct modules.
Now the question I have for Revel is is it possible to fetch ALL language strings for a given module and given locale? For example pull all home strings for en-US.
EDIT:
I would like the output (something I can return to the client) a key:value string of translations.
Any guidance would be appreciated.
It seems to me that revel uses messaged based translation (just like gettext does), so you need
the original string to get the translation. These strings are stored in Config objects,
which are themselves stored in messages of i18n.go, sorted by language.
As you can see, this mapping is not exported, so you can't access it. The best way
to fix this is to write a function for what you want (getting the config by supplying a language)
or exporting one of the existing functions and create a pull request for revel.
You may workaround this by copying the code of loadMessageFile or by forking your version
of revel and exporting loadMessageFile or parseMessagesFile. This also is a great opportunity
to create a pull request.
Note that the localizations are stored in a INI file format parsed by robfig/config,
so manually parsing is also an option (although not recommended).

Manual Url Culture Rewriting in DotNetNuke Request

I'm working with dotnetnuke 7.
I'm not using any rewriting modules and don't want to use them.
When content localization is enabled, url has the following view:
my_training_host/en-us/my-page.aspx
I want to change manually the display url so, that instead of full culture in query, the two letter culture (neutral culture) will show:
my_training_host/en/my-page.aspx
Does anyone have similar problem ?
If you ever change your mind about using a rewriting module, UrlMaster is the module for that. If not, then DNN 7.1 now adds support for creating url providers as extensions. More details at http://www.dnnsoftware.com/blog/cid/154604/Introducing-DNN-Extension-URL-Providers
I am using Open URL Rewriter for DNN - it does exactly what you ask for with it's default installation - no further config required.
And it's open source in comparison with UrlMaster.
In case of you use version 1.3.1 of Open URL Rewriter with DNN 7.04 to get two letters only for multilingual sites you have to make sure:
you create site aliases for each language with the two letter part you desire and
enable those entries as primary aliases (you need one primary alias for each language), for example for two languages (en & fr) you need to set three primary aliases like the following:
✔ www.yourdomain.com
✔ www.yourdomain.com/en us-US
✔ www.yourdomain.com/fr fr-FR

Resources