Skip to content

Commit

Permalink
Merge pull request #352 from SebastianGrans/master
Browse files Browse the repository at this point in the history
A new i18n management
  • Loading branch information
nate-parrott committed Mar 2, 2015
2 parents 06bc665 + 4109948 commit 6114e17
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 22 deletions.
3 changes: 3 additions & 0 deletions 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)
3 changes: 0 additions & 3 deletions PluginDirectories/1/weather.bundle/fixme_examples_fr.txt

This file was deleted.

4 changes: 0 additions & 4 deletions PluginDirectories/1/weather.bundle/fixme_strings_fr.json

This file was deleted.

18 changes: 15 additions & 3 deletions PluginDirectories/1/weather.bundle/plugin.py 100755 → 100644
Expand Up @@ -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-->", location)
# .replace("<!--UNITS-->", "metric" if use_metric() else "imperial")
# .replace("<!--APPEARANCE-->", "dark" if dark_mode() else "light")
# .replace("<!--TIME-->", 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-->", location)
.replace("<!--UNITS-->", "metric" if use_metric() else "imperial")
.replace("<!--APPEARANCE-->", "dark" if dark_mode() else "light")
.replace("<!--TIME-->", time)
# OpenWeatherMap supports a range of different languages.
#.replace("<!--locale-->") # Future implementation?
.replace("\"<!--WEEKDAYS-->\"", i18n.localstr('[\'Sunday\', \'Monday\', \'Tuesday\', \'Wednesday\', \'Thursday\', \'Friday\', \'Saturday\']'))
.replace("\"<!--NOW-->\"", i18n.localstr('[\'Now\', \'Today\']'))
.replace("<!--LOCALE-->", i18n.localstr("locale"))
)



return {
"title": title,
"html": html,
Expand Down
5 changes: 4 additions & 1 deletion 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']"
}
7 changes: 7 additions & 0 deletions 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']"
}
5 changes: 4 additions & 1 deletion 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']"
}
23 changes: 13 additions & 10 deletions PluginDirectories/1/weather.bundle/weather.html
Expand Up @@ -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";
Expand Down Expand Up @@ -72,10 +72,12 @@
var units = "<!--UNITS-->";
var appearance = "<!--APPEARANCE-->";
var time = "<!--TIME-->";
// var locale = "<!--LOCALE-->" // Future implementation?
var locale = "<!--LOCALE-->"
var weekdays = "<!--WEEKDAYS-->";
var nowstring = "<!--NOW-->";

// Lots of useful debugging stuff.
// var debugging = false;
// var debugging = true;
// var preset = false;
// if (preset) {
// var locationName = "uppsala";
Expand All @@ -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() {
Expand Down Expand Up @@ -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++) {
Expand Down

0 comments on commit 6114e17

Please sign in to comment.