问题在属性文件中的特殊字符。

huangapple go评论82阅读模式
英文:

Problem with special characters in properties file

问题

I have properties files for translation. One file is in English, the other one in Swedish. For each page I want translation for I have separate properties files e.g. home.properties, home_en.properties, help.properties, help_en.properties. I also have the files under source control (github).

When I open a certain file I get the text in odd format e.g.:

lbl_draftsMan=Föredragande
lbl_draftsManEpost=Epost föredragande

alternative text for the English file is:

lbl_draftsMan=Presenter
lbl_draftsManEpost=Email presenter

I notice in Github that the text in the Swedish file is normal there:

lbl_draftsMan=Föredragande
lbl_draftsManEpost=Epost föredragande

I have the following properties for the file:

Field Name: $MimeCharSet
Data Type: Text
Data Length: 5 bytes
Seq Num: 5
Dup Item ID: 0
Field Flags: SIGN SUMMARY

"UTF-8"

Other properties files the same setting but there I do not have the coded character problem.

What is the reason for this? I assume Domino Designer is the root of the problem?

英文:

I have properties files for translation. One file is in English, the other one in Swedish. For each page I want translation for I have separate properties files e.g. home.properties, home_en.properties, help.properties, help_en.properties. I also have the files under source control (github).

When I open a certain file I get the text in odd format e.g.:

  1. lbl_draftsMan=Föredragande
  2. lbl_draftsManEpost=Epost föredragande

alternative text for the English file is:

  1. lbl_draftsMan=Presenter
  2. lbl_draftsManEpost=Email presenter

I notice in Github that the text in the Swedish file is normal there:

  1. lbl_draftsMan=Föredragande
  2. lbl_draftsManEpost=Epost föredragande

I have the following properties for the file:

  1. Field Name: $MimeCharSet
  2. Data Type: Text
  3. Data Length: 5 bytes
  4. Seq Num: 5
  5. Dup Item ID: 0
  6. Field Flags: SIGN SUMMARY
  7. "UTF-8"

Other properties files the same setting but there I do not have the coded character problem.

What is the reason for this? I assume Domino Designer is the root of the problem?

答案1

得分: 1

我们在德国的属性文件中遇到了类似的问题。尽管我们的设置是UTF-8,但特殊字符显示不正确。只有当我们使用Unicode转义输入特殊字符时,特殊字符才会正确显示(例如 ö --> \u00f6)。

英文:

We had a similiar problem with our german property files. Although our setting was UTF-8, umlauts were displayed incorrectly. Only when we entered the umlauts in Unicode escape were the umlauts displayed correctly (e.g. ö --> \u00f6)

答案2

得分: 0

Property files are not UTF-8, you need to encode your content. Easiest way is a small standalone Java app reading you UTF-8 source and writing out using the Properties class. It takes care of encoding.

Updates:

  1. import java.io.FileWriter;
  2. import java.io.Writer;
  3. import java.nio.charset.StandardCharsets;
  4. import java.nio.file.Path;
  5. import java.util.Properties;
  6. import java.util.Scanner;
  7. /*
  8. * Demo of handling UTF-8 properties
  9. */
  10. public class Umlaut {
  11. public static void main(String[] args) throws Exception {
  12. Umlaut u = new Umlaut();
  13. u.run("source.txt", "target.properties");
  14. }
  15. void run(String sourceFileName, String targetFileName) throws Exception {
  16. try (Writer writer = new FileWriter(targetFileName, StandardCharsets.ISO_8859_1);
  17. Scanner scanner = new Scanner(Path.of(sourceFileName), StandardCharsets.UTF_8)) {
  18. Properties properties = new Properties();
  19. while (scanner.hasNextLine()) {
  20. String line = scanner.nextLine();
  21. String[] splits = line.split("=");
  22. properties.setProperty(splits[0], escape(splits[1]));
  23. }
  24. properties.store(writer, "Transformed");
  25. }
  26. }
  27. String escape(String source) {
  28. final StringBuilder b = new StringBuilder();
  29. for (int i = 0; i < source.length(); i++) {
  30. char c = source.charAt(i);
  31. convert(c, b);
  32. }
  33. return b.toString();
  34. }
  35. void convert(char source, StringBuilder b) {
  36. if (source <= 0x7E) {
  37. b.append(source);
  38. return;
  39. }
  40. b.append("\\u");
  41. String hex = "0000" + Integer.toHexString(source);
  42. b.append(hex.substring(hex.length() - 4));
  43. }
  44. }
英文:

Property files are not UTF-8, you need to encode your content. Easiest way is a small standalone Java app reading you UTF-8 source and writing out using the Properties class. It takes care of encoding

Updates:

  1. import java.io.FileWriter;
  2. import java.io.Writer;
  3. import java.nio.charset.StandardCharsets;
  4. import java.nio.file.Path;
  5. import java.util.Properties;
  6. import java.util.Scanner;
  7. /*
  8. * Demo of handling UTF-8 properties
  9. */
  10. public class Umlaut {
  11. public static void main(String[] args) throws Exception {
  12. Umlaut u = new Umlaut();
  13. u.run(&quot;source.txt&quot;, &quot;target.properties&quot;);
  14. }
  15. void run(String sourceFileName, String targetFileName) throws Exception {
  16. try (Writer writer = new FileWriter(targetFileName, StandardCharsets.ISO_8859_1);
  17. Scanner scanner = new Scanner(Path.of(sourceFileName), StandardCharsets.UTF_8)) {
  18. Properties properties = new Properties();
  19. while (scanner.hasNextLine()) {
  20. String line = scanner.nextLine();
  21. String[] splits = line.split(&quot;=&quot;);
  22. properties.setProperty(splits[0], escape(splits[1]));
  23. }
  24. properties.store(writer, &quot;Transformed&quot;);
  25. }
  26. }
  27. String escape(String source) {
  28. final StringBuilder b = new StringBuilder();
  29. for (int i = 0; i &lt; source.length(); i++) {
  30. char c = source.charAt(i);
  31. convert(c, b);
  32. }
  33. return b.toString();
  34. }
  35. void convert(char source, StringBuilder b) {
  36. if (source &lt;= 0x7E) {
  37. b.append(source);
  38. return;
  39. }
  40. b.append(&quot;\\u&quot;);
  41. String hex = &quot;0000&quot; + Integer.toHexString(source);
  42. b.append(hex.substring(hex.length() - 4));
  43. }
  44. }

huangapple
  • 本文由 发表于 2023年4月13日 19:01:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76004646.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定