Skip to content

Commit

Permalink
Fuzzyw translation (#3)
Browse files Browse the repository at this point in the history
* Update metadata.json

* Update ChangeLog

* Update fuzzyw.app.js

* Update de_DE.json

* Update de_DE.json
  • Loading branch information
sir-indy committed Apr 20, 2022
1 parent 7f657a3 commit 6c77b7b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 28 deletions.
1 change: 1 addition & 0 deletions apps/fuzzyw/ChangeLog
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
0.01: First release
0.02: Move translations to locale module
59 changes: 36 additions & 23 deletions apps/fuzzyw/fuzzyw.app.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
// adapted from https://github.com/hallettj/Fuzzy-Text-International/
const fuzzy_strings = require("Storage").readJSON("fuzzy_strings.json");

const SETTINGS_FILE = "fuzzyw.settings.json";
let settings = require("Storage").readJSON(SETTINGS_FILE,1)|| {'language': 'System', 'alignment':'Centre'};

if (settings.language == 'System') {
settings.language = require('locale').name;
}

let fuzzy_string = fuzzy_strings[settings.language];
let fuzzy_string = {
"hours":[
/*LANG*/"twelve",
/*LANG*/"one",
/*LANG*/"two",
/*LANG*/"three",
/*LANG*/"four",
/*LANG*/"five",
/*LANG*/"six",
/*LANG*/"seven",
/*LANG*/"eight",
/*LANG*/"nine",
/*LANG*/"ten",
/*LANG*/"eleven"
],
"minutes":[
/*LANG*/"*$1 o'clock",
/*LANG*/"five past *$1",
/*LANG*/"ten past *$1",
/*LANG*/"quarter past *$1",
/*LANG*/"twenty past *$1",
/*LANG*/"twenty five past *$1",
/*LANG*/"half past *$1",
/*LANG*/"twenty five to *$2",
/*LANG*/"twenty to *$2",
/*LANG*/"quarter to *$2",
/*LANG*/"ten to *$2",
/*LANG*/"five to *$2"
]
};

let text_scale = 3.5;
let timeout = 2.5*60;
let drawTimeout;

Expand All @@ -24,36 +46,27 @@ function queueDraw(seconds) {

const h = g.getHeight();
const w = g.getWidth();
let align_mode = 0;
let align_pos = w/2;
if (settings.alignment =='Left') {
align_mode = -1;
align_pos = 0;
} else if (settings.alignment == 'Right') {
align_mode = 1;
align_pos = w;
}

function getTimeString(date) {
let segment = Math.round((date.getMinutes()*60 + date.getSeconds() + 1)/300);
let hour = date.getHours() + Math.floor(segment/12);
f_string = fuzzy_string.minutes[segment % 12];
if (f_string.includes('$1')) {
f_string = f_string.replace('$1', fuzzy_string.hours[(hour) % 24]);
f_string = f_string.replace('$1', fuzzy_string.hours[(hour) % 12]);
} else {
f_string = f_string.replace('$2', fuzzy_string.hours[(hour + 1) % 24]);
f_string = f_string.replace('$2', fuzzy_string.hours[(hour + 1) % 12]);
}
return f_string;
}

function draw() {
let time_string = getTimeString(new Date()).replace('*', '');
// print(time_string);
g.setFont('Vector', (h-24*2)/fuzzy_string.text_scale);
g.setFontAlign(align_mode, 0);
g.setFont('Vector', (h-24*2)/text_scale);
g.setFontAlign(0, 0);
g.clearRect(0, 24, w, h-24);
g.setColor(g.theme.fg);
g.drawString(g.wrapString(time_string, w).join("\n"), align_pos, h/2);
g.drawString(g.wrapString(time_string, w).join("\n"), w/2, h/2);
queueDraw(timeout);
}

Expand Down
5 changes: 2 additions & 3 deletions apps/fuzzyw/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id":"fuzzyw",
"name":"Fuzzy Text Clock",
"shortName": "Fuzzy Text",
"version": "0.01",
"version": "0.02",
"description": "An imprecise clock for when you're not in a rush",
"readme": "README.md",
"icon":"fuzzyw.png",
Expand All @@ -14,7 +14,6 @@
"storage": [
{"name":"fuzzyw.app.js","url":"fuzzyw.app.js"},
{"name":"fuzzyw.settings.js","url":"fuzzyw.settings.js"},
{"name":"fuzzyw.img","url":"fuzzyw.icon.js","evaluate":true},
{"name":"fuzzy_strings.json","url":"fuzzy_strings.json"}
{"name":"fuzzyw.img","url":"fuzzyw.icon.js","evaluate":true}
]
}
31 changes: 29 additions & 2 deletions lang/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,37 @@
"Music": "Musik",
"color": "Farbe",
"off": "aus",
"Theme": "Thema"
"Theme": "Thema",
"one": "eins",
"two": "zwei",
"three": "drei",
"four": "vier",
"five": "fünf",
"six": "sechs",
"seven": "sieben",
"eight": "acht",
"nine": "neun",
"ten": "zehn",
"eleven": "elf",
"twelve": "zwölf"
},
"alarm": {
"//": "App-specific overrides",
"rpt": "Wdh."
},
"fuzzyw": {
"//": "App-specific overrides",
"*$1 o'clock": "*$1 uhr",
"five past *$1": "fünf nach *$1",
"ten past *$1": "zehn nach *$1",
"quarter past *$1": "viertel nach *$1",
"twenty past *$1": "zwanzig nach *$1",
"twenty five past *$1": "fünf for halb *$2",
"half past *$1": "halb *$2",
"twenty five to *$2": "fünf nach halb *$2",
"twenty to *$2": "zwanzig vor *$2",
"quarter to *$2": "viertel vor *$2",
"ten to *$2": "zehn vor *$2",
"five to *$2": "fünf vor *$2"
}
}
}

0 comments on commit 6c77b7b

Please sign in to comment.