From 41099489b70697918bb11ffc2c39806109b055f8 Mon Sep 17 00:00:00 2001 From: Sebastian Grans Date: Mon, 2 Mar 2015 00:32:30 +0100 Subject: [PATCH] A new i18n management Removed the localised html files. Now everything is managed by the python script with the strings.json dictionaries. Less cluttered and easier to add new translations. --- .../1/weather.bundle/examples_fr.txt | 3 +++ .../1/weather.bundle/fixme_examples_fr.txt | 3 --- .../1/weather.bundle/fixme_strings_fr.json | 4 ---- PluginDirectories/1/weather.bundle/plugin.py | 18 ++++++++++++--- .../1/weather.bundle/strings_de.json | 5 +++- .../1/weather.bundle/strings_fr.json | 7 ++++++ .../1/weather.bundle/strings_nl.json | 5 +++- .../1/weather.bundle/weather.html | 23 +++++++++++-------- 8 files changed, 46 insertions(+), 22 deletions(-) create mode 100644 PluginDirectories/1/weather.bundle/examples_fr.txt delete mode 100644 PluginDirectories/1/weather.bundle/fixme_examples_fr.txt delete mode 100644 PluginDirectories/1/weather.bundle/fixme_strings_fr.json mode change 100755 => 100644 PluginDirectories/1/weather.bundle/plugin.py create mode 100644 PluginDirectories/1/weather.bundle/strings_fr.json diff --git a/PluginDirectories/1/weather.bundle/examples_fr.txt b/PluginDirectories/1/weather.bundle/examples_fr.txt new file mode 100644 index 00000000..0741db16 --- /dev/null +++ b/PluginDirectories/1/weather.bundle/examples_fr.txt @@ -0,0 +1,3 @@ +Quel est le climat à ~location(Brooklyn) ~now(maintenant)? +Météo pour ~location(Shangai) ~now(maintenant) +temps ~location(paris) ~now(maintenant) diff --git a/PluginDirectories/1/weather.bundle/fixme_examples_fr.txt b/PluginDirectories/1/weather.bundle/fixme_examples_fr.txt deleted file mode 100644 index 74e7ed95..00000000 --- a/PluginDirectories/1/weather.bundle/fixme_examples_fr.txt +++ /dev/null @@ -1,3 +0,0 @@ -Quel est le climat à ~location(Brooklyn)? -Météo pour ~location(Shangai) -temps ~location(paris) diff --git a/PluginDirectories/1/weather.bundle/fixme_strings_fr.json b/PluginDirectories/1/weather.bundle/fixme_strings_fr.json deleted file mode 100644 index fe09ba88..00000000 --- a/PluginDirectories/1/weather.bundle/fixme_strings_fr.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "\"{0}\" weather": "\"{0}\" temps", - -} \ No newline at end of file diff --git a/PluginDirectories/1/weather.bundle/plugin.py b/PluginDirectories/1/weather.bundle/plugin.py old mode 100755 new mode 100644 index 9d6ac36c..cbd1cf41 --- a/PluginDirectories/1/weather.bundle/plugin.py +++ b/PluginDirectories/1/weather.bundle/plugin.py @@ -33,17 +33,29 @@ def results(parsed, original_query): # print >> sys.stderr, 'Interpreted the time as: ' + time # print >> sys.stderr, 'Interpreted the location as: ' + location + # title = i18n.localstr('"{0}" weather').format(location) + # html = ( + # open(i18n.find_localized_path("weather.html")).read().decode('utf-8') + # .replace("", location) + # .replace("", "metric" if use_metric() else "imperial") + # .replace("", "dark" if dark_mode() else "light") + # .replace("", time) + # ) + title = i18n.localstr('"{0}" weather').format(location) html = ( - open(i18n.find_localized_path("weather.html")).read().decode('utf-8') + open("weather.html").read().decode('utf-8') .replace("", location) .replace("", "metric" if use_metric() else "imperial") .replace("", "dark" if dark_mode() else "light") .replace("", time) - # OpenWeatherMap supports a range of different languages. - #.replace("") # Future implementation? + .replace("\"\"", i18n.localstr('[\'Sunday\', \'Monday\', \'Tuesday\', \'Wednesday\', \'Thursday\', \'Friday\', \'Saturday\']')) + .replace("\"\"", i18n.localstr('[\'Now\', \'Today\']')) + .replace("", i18n.localstr("locale")) ) + + return { "title": title, "html": html, diff --git a/PluginDirectories/1/weather.bundle/strings_de.json b/PluginDirectories/1/weather.bundle/strings_de.json index f08dd233..2d63acf6 100644 --- a/PluginDirectories/1/weather.bundle/strings_de.json +++ b/PluginDirectories/1/weather.bundle/strings_de.json @@ -1,4 +1,7 @@ { "\"{0}\" weather": "\"{0}\" Wetter", - "now": "heute" + "now": "heute", + "en": "de", + "['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']": "['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag']", + "['Now', 'Today']": "['Heute', 'Heute']" } \ No newline at end of file diff --git a/PluginDirectories/1/weather.bundle/strings_fr.json b/PluginDirectories/1/weather.bundle/strings_fr.json new file mode 100644 index 00000000..83631124 --- /dev/null +++ b/PluginDirectories/1/weather.bundle/strings_fr.json @@ -0,0 +1,7 @@ +{ + "\"{0}\" weather": "\"{0}\" temps", + "now": "maintenant", + "en": "fr", + "['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']": "['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi']", + "['Now', 'Today']": "['Maintenant', 'Aujourd\\u0027hui']" +} \ No newline at end of file diff --git a/PluginDirectories/1/weather.bundle/strings_nl.json b/PluginDirectories/1/weather.bundle/strings_nl.json index 516abd6f..4268dfe3 100644 --- a/PluginDirectories/1/weather.bundle/strings_nl.json +++ b/PluginDirectories/1/weather.bundle/strings_nl.json @@ -1,4 +1,7 @@ { "\"{0}\" weather": "\"{0}\" Weer", - "now": "nu" + "now": "nu", + "en": "nl", + "['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']": "['Zondag', 'Maandag', 'Dinsdag', 'Woensdag', 'Donderdag', 'Vrijdag', 'Zaterdag']", + "['Now', 'Today']": "['Nu', 'Vandaag']" } diff --git a/PluginDirectories/1/weather.bundle/weather.html b/PluginDirectories/1/weather.bundle/weather.html index d34b8560..4380d2ca 100644 --- a/PluginDirectories/1/weather.bundle/weather.html +++ b/PluginDirectories/1/weather.bundle/weather.html @@ -25,20 +25,20 @@ // Instead of writing the name of the day, it should write "Today" if (timestamp == "Today") { - return timestamp; + return nowstring[1]; } var d = (new Date(timestamp * 1000)).getDay(); - return ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][d]; + return weekdays[d]; } function hoursFromTimestamp(timestamp) { if (timestamp == "Now") { - return timestamp; + return nowstring[0]; } // getHours returns UTC. Adjust this with getTimezoneOffset. var d = (new Date(timestamp * 1000)).getHours()+(new Date().getTimezoneOffset()/60); - console.log(timestamp + " " + new Date(timestamp * 1000).getHours() + " " + d); + if (d < 10) { d = "0" + d + ":00"; @@ -72,10 +72,12 @@ var units = ""; var appearance = ""; var time = ""; - // var locale = "" // Future implementation? + var locale = "" + var weekdays = ""; + var nowstring = ""; // Lots of useful debugging stuff. - // var debugging = false; + // var debugging = true; // var preset = false; // if (preset) { // var locationName = "uppsala"; @@ -90,9 +92,11 @@ // console.log("time:" + time); // document.write("location:" + locationName); - // document.write("units:" + units); - // document.write("appearance:" + appearance); - // document.write("time:" + time); + // document.write("\nunits:" + units); + // document.write("\nappearance:" + appearance); + // document.write("\ntime:" + time); + // document.write("\nweekdays:" + weekdays); + // document.write("\nnow:" + nowstring); // } function load() { @@ -162,7 +166,6 @@ var laterDays = crel("div", {"id": "laterDays"}); if (time == "now") { - console.log(json.list[2].dt); json.list[0].dt = "Now"; // var el = crel("div", crel("div", {id: 'location'}, json.city.name + ", " + json.city.country), crel("div", {"id": "today"}, createHTMLForHours(json.list[0], 128)), laterDays); for (i = 01; i < 4; i++) {