Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix escaped characters in translations #569

Merged
merged 13 commits into from
Jan 9, 2019
2 changes: 1 addition & 1 deletion _locales/de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
<string name="ask_export_attachment">Anlage exportieren? Das Exportieren von Anhängen ermöglicht es allen anderen Anwendungen auf Ihrem Gerät, auf diese zuzugreifen.\n\nFortfahren? </string>
<string name="ask_block_contact">Diesen Kontakt blockieren? Du wirst keine Nachrichten mehr von diesem Kontakt erhalten.</string>
<string name="ask_unblock_contact">Diesen Kontakt freischalten? Nachrichten von diesem Kontakt werden dann wieder angezeigt.</string>
<string name="ask_delete_contacts">Kontakte löschen? Dadurch werden die ausgewählten Kontakte dauerhaft gelöscht.\n\n\Kontakte mit laufenden Chats und Kontakte aus dem Adressbuch des Systems können nicht dauerhaft gelöscht werden.</string>
<string name="ask_delete_contacts">Kontakte löschen? Dadurch werden die ausgewählten Kontakte dauerhaft gelöscht.\n\nKontakte mit laufenden Chats und Kontakte aus dem Adressbuch des Systems können nicht dauerhaft gelöscht werden.</string>
<string name="ask_start_chat_with">Chat mit %1$s starten?</string>


Expand Down
6 changes: 3 additions & 3 deletions _locales/sq.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<string name="menu_new_group">Grup i ri</string>
<string name="menu_new_verified_group">Grup i ri i verifikuar</string>
<string name="menu_send">Dërgoje</string>
<string name="menu_toggle_keyboard">Shfaq/fshih tastierë <em>emoji</em></string>
<string name="menu_toggle_keyboard">Shfaq/fshih tastierë emoji</string>
<string name="menu_edit_group">Përpunoni grup</string>
<string name="menu_archive_chat">Arkivoje fjalosjen</string>
<string name="menu_unarchive_chat">Çarkivoje fjalosjen</string>
Expand Down Expand Up @@ -319,7 +319,7 @@
<string name="pref_read_receipts">Lexoni dëftesa</string>
<string name="pref_read_receipts_explain">Nëse leximi i dëftesave është i çaktivizuar, s’do të jeni në gjendje të shihni mesazh "Lexoni dëftesa" prej të tjerësh</string>
<string name="pref_manage_keys">Administroni kyçe</string>
<string name="pref_use_system_emoji">Përdor <em>emoji</em> sistemi</string>
<string name="pref_use_system_emoji">Përdor emoji sistemi</string>
<string name="pref_use_system_emoji_explain">Çaktivizo mbulimin e brendshëm Delta Chat për emoji-t</string>
<string name="pref_communication">Komunikim</string>
<string name="pref_chats">Fjalosje</string>
Expand Down Expand Up @@ -389,7 +389,7 @@
<string name="qrscan_ask_fingerprint_ask_oob">Të verifikohet kontakti dhe të fillohet të bisedohet me \"%1$s\"?</string>
<string name="qrscan_ask_chatting_fingerprint_ok">Kontakti \"%1$s\" u verifikua. Të fillohet të bisedohet?</string>
<string name="qrscan_fingerprint_mismatch">Shenjat e gishtave të skanuar \"nuk përputhen\" me shenjat e gishtave parë së fundi për \"%1$s\".</string>
<string name="qrscan_no_addr_found">Ky kod QR përmban shenja gishtash, por jo adresë email.\n\nPër një verifikim <em>out-of-band</em>, ju lutemi, së pari vendosni me marrësin një lidhje të fshehtëzuar.</string>
<string name="qrscan_no_addr_found">Ky kod QR përmban shenja gishtash, por jo adresë email.\n\nPër një verifikim out-of-band, ju lutemi, së pari vendosni me marrësin një lidhje të fshehtëzuar.</string>
<string name="qrscan_contains_text">Tekst kodi QR të skanuar:\n\n%1$s</string>
<string name="qrscan_contains_url">URL kodi QR të skanuar:\n\n%1$s</string>
<string name="qrscan_fingerprint_label">Shenja gishtash</string>
Expand Down
4 changes: 2 additions & 2 deletions _locales/tr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,13 @@
<string name="welcome_intro2_headline">Bağımsız</string>
<string name="welcome_intro2_message">Hiç Delta Chat sunucusu yoktur. Uygulama, yalnızca posta sunucunuzu kullanır.</string>
<string name="welcome_intro3_headline">Hızlı</string>
<string name="welcome_intro3_message">İletileri saniyeler içinde gönderin.<br/>Hızlı arabirim.</string>
<string name="welcome_intro3_message">İletileri saniyeler içinde gönderin.\nHızlı arabirim.</string>
<string name="welcome_intro4_headline">Güçlü</string>
<string name="welcome_intro4_message">Sınırsız sohbetler, görüntüler, videolar, sesli iletiler ve daha fazlası. Çoklu istemci yetenekli.</string>
<!-- Translators: "free" as in freedom here, not "free" as in "free beer" -->
<string name="welcome_intro5_headline">Özgür</string>
<!-- Translators: "free" as in freedom here, not "free" as in "free beer" -->
<string name="welcome_intro5_message">Delta Chat sonsuza dek özgürdür.<br/>Açık kaynaklı. Reklâm yok. Abonelik yok. Satıcı kilidi yok.</string>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't have a new line in the original

<string name="welcome_intro5_message">Delta Chat sonsuza dek özgürdür. Açık kaynaklı. Reklâm yok. Abonelik yok. Satıcı kilidi yok.</string>
<string name="welcome_intro6_headline">Şifreli</string>
<string name="welcome_intro6_message">Tüm yaygın algoritmalarla şifrelidir. İletiler sunucularınızda kalır.</string>
<string name="welcome_intro7_headline">Güvenilir</string>
Expand Down
5 changes: 4 additions & 1 deletion bin/convert-translations-from-xml-to-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ function xmlToJson (filename) {
if (!name) return error(string)
let text = string._text
if (typeof text === 'string') {
text = text.replace(/\\n/g, '\n')
text = text.replace(new RegExp('\\\\n', 'g'), '\n')
text = text.replace(new RegExp("\\\\'", 'g'), "'")
text = text.replace(new RegExp('\\\\\\"', 'g'), '"')
text = text.replace(new RegExp('\\\\', 'g'), '')
}
res[name] = {
'message': text
Expand Down
52 changes: 40 additions & 12 deletions test/unit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,48 @@ test('that translation files are valid json', t => {
jsonFiles.map(name),
'each xml file has a corresponding json file'
)
const testFile = file => {
let json = null
try {
json = require(file)
} catch (e) {
console.error(e.message)
return false
Copy link
Member Author

@ralphtheninja ralphtheninja Jan 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First test makes sure the file is valid json.

}
return Object.keys(json).every(k1 => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For every resource ..

const v1 = json[k1]
return Object.keys(v1).every(k2 => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.. every key of that resource (e.g. "message" etc) ..

const v2 = v1[k2]
if (typeof v2 !== 'string') {
console.error(
`> ${JSON.stringify(v2)} not a string (${file} -> ${k1} -> ${k2})`
)
return false
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be a string ..

function testString (str) {
const regex = new RegExp(str, 'g')
const match = regex.exec(v2)
if (match) {
console.error(`> ${JSON.stringify(v2)} contains ${str} (${file} -> ${k1} -> ${k2}) (index: ${match.index})`)
return false
}
return true
}

if (!testString('\\\\n')) return false
if (!testString("\\\\'")) return false
if (!testString('\\\\\\"')) return false
if (!testString('\\\\')) return false
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it shouldn't contain these.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could probably refactor this into one return statement. Up to you guys.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine with multiple returns to me


return true
})
})
}
t.is(
jsonFiles.every(f => {
let ok = false
const fullPath = path.join(dir, f)
try {
require(fullPath)
ok = true
} catch (e) {
console.error(e)
}
return ok
}),
jsonFiles.every(f => testFile(path.join(dir, f))),
true,
'json is valid'
'valid json and valid strings'
)
t.end()
})
Expand Down