0

I want to give Turkish character as a value in my .properties file. But outcome not shown well

I put into properties file

myvalue=BİLGEHAN

Outcome B?LGEHAN

I found some solutions in stackoverflow. But I want to clarify

I tried to add properties file encoding try both of them UTF-8 and ISO-8859-1 not working

@PropertySource(
    value = {"my.properties"},
    encoding = "UTF-8"
)

I set -Dfile.encoding=UTF-8 it is not working native2ascii conversion work

Only thing I can do I use native2ascii and convert my value to ascii format and then my message shows well

I want to clarify is there any way to use my special characters in properties file or is this only way to do convert ascii and use it?

UTF-8 encoding of application.properties attributes in Spring-Boot

M. Deinum
  • 115,695
  • 22
  • 220
  • 224
Bilgehan
  • 1,135
  • 1
  • 14
  • 41
  • Changing the encoding doesn't help if your file isn't saved as UTF-8. Make sure that your properties file is an actual `UTF-8` file. Also on older java (and Spring) version the properties are expected to be in ISO-8859-1 format (the default and standard for a long time). The `-Dfile.encoding=UTF-8` should kind of work but that might depend on how you are launching things. – M. Deinum Jan 05 '22 at 09:29
  • Hi I use intellij 2021 and spring 2.5 so I try in newer versions – Bilgehan Jan 05 '22 at 10:29

2 Answers2

0

Default encoding for .properties files can be changed in intellij with

File->Settings->Editor->File Encodings

After changing it to UTF-8 .properties files can be saved as UTF-8.

msbgnr
  • 49
  • 4
0

The issue:

  • Historically a stupidity happened and the encoding of .properties files was in ISO-8859-1, Latin-1. For Turkish, Latin-3, one would need to encode the special characters as \uXXXX (native2ascii).
  • Recent java versions now first try to read the .properties files as UTF-8. This really is ideal. And I recommend going with that. Then working with Cyrillic or Arabic resource bundles will be much easier.

For that to work the editor too has to use the UTF-8 encoding. Sometimes already java sources are edited in UTF-8, but properties files using ISO-8859-1 because of the java language standard. So check the IDE. Maybe use Notepad++ or an other encoding aware editor to check for the encoding.

You can use native2ascii both for encoding and decoding specifying your own encoding. Hence a conversion to UTF-8 is simple.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138