0

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?

  • AFAIK messages files are just .properties file and such syntax is not allowed. You have control over the keys though, don't you? Just don't use such keys, stick to only alphanum like `hello_world_parenthesis`. – Gaël J Dec 06 '22 at 19:29
  • @GaëlJ In this case I have been given specific messages that needs to be translated and those messages include these special characters. – Prakhar Singh Dec 06 '22 at 19:31
  • I think you should create keys, use the given message as default value for the key (messages file) and add translations for each language. Using "full sentence" as keys is gonna be a pain. – Gaël J Dec 06 '22 at 21:23

1 Answers1

0

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

Andrii Bodnar
  • 1,672
  • 2
  • 17
  • 24