Special character in key in the conf file for Internationlization in play framework

74 views Asked by At

I am trying to use the Internationalization feature of the Play Framework.

It involves the creation of a new conf file for each language that we want to support. Example for french we create a messages.fr file in the conf folder.

Inside it we define key-values like this:

Hello.World = 'Bonjour le monde'

Now the issue is that I have lines that contain characters like "," and "(" and if these are included in the key then we get the error in parsing from the MessageApi

Example

Hello.(World) = 'Bonjour (le monde)'

Here the "(" before and after World is throwing an error while parsing.

Anyone having any idea how we could achieve this?

1

There are 1 answers

0
Andrii Bodnar On

Try to escape these special characters:

Hello.\(World\) = 'Bonjour (le monde)'

Other examples:

string_one = String for translation 1
string_two = one + one \= two
# String key with spaces
key\ with\ spaces = This is the value that could be looked up with the key "key with spaces".
# Backslash in value should be escaped by another backslash
path=c:\\wiki\\ templates

Also, you can try to escape special characters by using Java Unicode:

Hello.\u0028World\u0029 = 'Bonjour (le monde)'

Reference - How to escape the equals sign in properties files