diff --git a/internal/translations/language_file.android.go b/internal/translations/language_file.android.go index 43c3e17..0d240c8 100644 --- a/internal/translations/language_file.android.go +++ b/internal/translations/language_file.android.go @@ -16,7 +16,7 @@ func (f *androidLanguageFile) Write(translations *translationData) error { } func (f *androidLanguageFile) write(translation *translation, io io.Writer) error { - regex := regexp.MustCompile(`%([0-9]+)`) + regex := regexp.MustCompile(`%%([0-9]+)`) escape := strings.NewReplacer( "&", "&", @@ -24,17 +24,20 @@ func (f *androidLanguageFile) write(translation *translation, io io.Writer) erro ">", ">", "\"", "\\\"", "'", "\\'", - "\n", "\\n") + "\n", "\\n", + "%", "%%") - _, err := io.Write([]byte("\n")) + _, err := io.Write([]byte("\n\n")) if err != nil { return err } for _, k := range translation.keys { key := strings.ToLower(k) - value := regex.ReplaceAllString(translation.get(k), "%${1}$$s") - _, err = io.Write([]byte(fmt.Sprintf("\t%s\n", key, escape.Replace(value)))) + translationValue := translation.get(k) + escapedValue := escape.Replace(translationValue) + value := regex.ReplaceAllString(escapedValue, "%${1}$$s") + _, err = io.Write([]byte(fmt.Sprintf(" %s\n", key, value))) if err != nil { return err } diff --git a/internal/translations/language_file_test.go b/internal/translations/language_file_test.go index 8c1a1ff..55c5d9b 100644 --- a/internal/translations/language_file_test.go +++ b/internal/translations/language_file_test.go @@ -127,7 +127,7 @@ func TestLanguageFileWriteInputFile(t *testing.T) { } func TestEscapingSingleColumn(t *testing.T) { - output := "\n\tAnother string including a | even.\n\tThis is a longer sentence, which includes a comma.\n\n" + output := "\n\n Another string including a | even.\n This is a longer sentence, which includes a comma.\n\n" outputPath := "../../build/out.csv" inputPath := "../../build/test.csv" err := os.WriteFile("../../build/test.csv", []byte("key,en\nTHIS,\"This is a longer sentence, which includes a comma.\"\nTHAT,Another string including a | even."), 0777) @@ -155,7 +155,7 @@ func TestEscapingSingleColumn(t *testing.T) { } func TestEscapingAllColumns(t *testing.T) { - output := "\n\tAnother string including a | even.\n\tThis is a longer sentence, which includes a comma.\n\n" + output := "\n\n Another string including a | even.\n This is a longer sentence, which includes a comma.\n\n" outputPath := "../../build/out.csv" inputPath := "../../build/test.csv" err := os.WriteFile("../../build/test.csv", []byte("\"key\",\"en\"\n\"THIS\",\"This is a longer sentence, which includes a comma.\"\n\"THAT\",\"Another string including a | even.\""), 0777) diff --git a/internal/translations/testdata/android-da.expected b/internal/translations/testdata/android-da.expected index db50314..daa0c0b 100644 --- a/internal/translations/testdata/android-da.expected +++ b/internal/translations/testdata/android-da.expected @@ -1,8 +1,10 @@ + - Noget - Noget med , - Det er som & og <b>fremhævet</b> \"tekst\" eller 官话 - Noget med %1$s og %2$s - Tekst\nmed\nline\nskift - Noget + Noget + Noget med , + Det er som & og <b>fremhævet</b> \"tekst\" eller 官话 + Noget med %1$s og %2$s + Noget med %% %1$s %%%2$s + Tekst\nmed\nline\nskift + Noget diff --git a/internal/translations/testdata/android-empty.expected b/internal/translations/testdata/android-empty.expected index 8542005..045e125 100644 --- a/internal/translations/testdata/android-empty.expected +++ b/internal/translations/testdata/android-empty.expected @@ -1,2 +1,3 @@ + diff --git a/internal/translations/testdata/android-en.expected b/internal/translations/testdata/android-en.expected index bd8cb58..18f5112 100644 --- a/internal/translations/testdata/android-en.expected +++ b/internal/translations/testdata/android-en.expected @@ -1,8 +1,10 @@ + - Something - Something with , - It\'s like & and <b>bold</b> \"text\" or 官话 - Something with %1$s and %2$s - Text\nwith\nnew\nlines - Something + Something + Something with , + It\'s like & and <b>bold</b> \"text\" or 官话 + Something with %1$s and %2$s + Something with %% %1$s %%%2$s + Text\nwith\nnew\nlines + Something diff --git a/internal/translations/testdata/fill-in/android-da.expected b/internal/translations/testdata/fill-in/android-da.expected index a19768f..6e4e8c5 100644 --- a/internal/translations/testdata/fill-in/android-da.expected +++ b/internal/translations/testdata/fill-in/android-da.expected @@ -1,4 +1,5 @@ + - Noget - Something only in English + Noget + Something only in English diff --git a/internal/translations/testdata/fill-in/android-en.expected b/internal/translations/testdata/fill-in/android-en.expected index 4369c54..7e604f2 100644 --- a/internal/translations/testdata/fill-in/android-en.expected +++ b/internal/translations/testdata/fill-in/android-en.expected @@ -1,4 +1,5 @@ + - Something - Something only in English + Something + Something only in English diff --git a/internal/translations/testdata/input.csv b/internal/translations/testdata/input.csv index 332f48a..dfaca05 100644 --- a/internal/translations/testdata/input.csv +++ b/internal/translations/testdata/input.csv @@ -2,6 +2,7 @@ KEY,UPDATE NEEDED,EN,DA,COMMENT SOMETHING,,Something,Noget, SOMETHING_ESCAPED,,"Something with ,","Noget med ,", SOMETHING_WITH_ARGUMENTS,,Something with %1 and %2,Noget med %1 og %2, +SOMETHING_WITH_ESCAPED_PERCENTAGE,,Something with % %1 %%2,Noget med % %1 %%2, SOMETHING_FOR_XML,,"It's like & and bold ""text"" or 官话","Det er som & og fremhævet ""tekst"" eller 官话", WATCH_OUT_FOR_NEW_LINES,,"Text with diff --git a/internal/translations/testdata/ios-da.expected b/internal/translations/testdata/ios-da.expected index d722e63..2edf80d 100644 --- a/internal/translations/testdata/ios-da.expected +++ b/internal/translations/testdata/ios-da.expected @@ -2,5 +2,6 @@ "SOMETHING_ESCAPED" = "Noget med ,"; "SOMETHING_FOR_XML" = "Det er som & og fremhævet \"tekst\" eller 官话"; "SOMETHING_WITH_ARGUMENTS" = "Noget med %1 og %2"; +"SOMETHING_WITH_ESCAPED_PERCENTAGE" = "Noget med % %1 %%2"; "WATCH_OUT_FOR_NEW_LINES" = "Tekst\nmed\nline\nskift"; "iOSCaseSensitiveKey" = "Noget"; diff --git a/internal/translations/testdata/ios-en.expected b/internal/translations/testdata/ios-en.expected index 2817542..fde9930 100644 --- a/internal/translations/testdata/ios-en.expected +++ b/internal/translations/testdata/ios-en.expected @@ -2,5 +2,6 @@ "SOMETHING_ESCAPED" = "Something with ,"; "SOMETHING_FOR_XML" = "It's like & and bold \"text\" or 官话"; "SOMETHING_WITH_ARGUMENTS" = "Something with %1 and %2"; +"SOMETHING_WITH_ESCAPED_PERCENTAGE" = "Something with % %1 %%2"; "WATCH_OUT_FOR_NEW_LINES" = "Text\nwith\nnew\nlines"; "iOSCaseSensitiveKey" = "Something"; diff --git a/internal/translations/testdata/ios-swift.expected b/internal/translations/testdata/ios-swift.expected index ef6009f..e63e8ed 100644 --- a/internal/translations/testdata/ios-swift.expected +++ b/internal/translations/testdata/ios-swift.expected @@ -5,6 +5,7 @@ public struct Translations { static let SOMETHING_ESCAPED = NSLocalizedString("SOMETHING_ESCAPED", comment: "") static let SOMETHING_FOR_XML = NSLocalizedString("SOMETHING_FOR_XML", comment: "") static func SOMETHING_WITH_ARGUMENTS(_ p1: String, _ p2: String) -> String { return NSLocalizedString("SOMETHING_WITH_ARGUMENTS", comment: "").replacingOccurrences(of: "%1", with: p1).replacingOccurrences(of: "%2", with: p2) } + static func SOMETHING_WITH_ESCAPED_PERCENTAGE(_ p1: String, _ p2: String) -> String { return NSLocalizedString("SOMETHING_WITH_ESCAPED_PERCENTAGE", comment: "").replacingOccurrences(of: "%1", with: p1).replacingOccurrences(of: "%2", with: p2) } static let WATCH_OUT_FOR_NEW_LINES = NSLocalizedString("WATCH_OUT_FOR_NEW_LINES", comment: "") static let iOSCaseSensitiveKey = NSLocalizedString("iOSCaseSensitiveKey", comment: "") } diff --git a/internal/translations/testdata/json-en.expected b/internal/translations/testdata/json-en.expected index b91d899..2691f83 100644 --- a/internal/translations/testdata/json-en.expected +++ b/internal/translations/testdata/json-en.expected @@ -4,5 +4,6 @@ "something_escaped": "Something with ,", "something_for_xml": "It's like \u0026 and \u003cb\u003ebold\u003c/b\u003e \"text\" or 官话", "something_with_arguments": "Something with %1 and %2", + "something_with_escaped_percentage": "Something with % %1 %%2", "watch_out_for_new_lines": "Text\nwith\nnew\nlines" } \ No newline at end of file