Skip to content

Instantly share code, notes, and snippets.

@minorua
Created July 1, 2016 01:59
Show Gist options
  • Save minorua/118851c93c641be4f7585d33cb70bc8f to your computer and use it in GitHub Desktop.
Save minorua/118851c93c641be4f7585d33cb70bc8f to your computer and use it in GitHub Desktop.
[QGIS-tr] Create a translation message list
// [QGIS] 翻訳メッセージ一覧を作成する
// Last update: 2016-07-01
// 1. Google Chromeを開く。
// 2. 次のURLにアクセスしてメッセージ一覧をJSON形式で取得する (最終更新日時・翻訳者情報付き)。Transifexアカウントでの認証が必要。
// http://www.transifex.com/api/2/project/QGIS/resource/qgis-application/translation/ja/strings/?details&last_update&user
// 3. CSV形式に変換してファイルに保存する。コンソールを開き次のコードをコピペする。
function escape_quote(text) {
return '"' + text.replace(/\n/g, "\\n").replace(/\"/g, '""') + '"';
}
var json = JSON.parse(document.body.innerText);
// var fieldNames = Object.keys(json[0]);
var fieldNames = ["context", "source_string", "translation", "last_update", "user", "pluralized", "occurrences"];
var data = [];
data.push(fieldNames.join(","));
json.forEach(function(row) {
var attrs = [];
fieldNames.forEach(function (fieldName) {
attrs.push(escape_quote((row[fieldName] || "").toString()));
});
data.push(attrs.join(","));
});
var a = document.createElement("a");
var file = new Blob([data.join("\n")], {type: "text/csv"});
a.href = URL.createObjectURL(file);
a.download = "messages.csv";
a.click();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment