From c8a310c29b630b8367aba99e19a51fbc32fabc49 Mon Sep 17 00:00:00 2001 From: vapormusic Date: Sat, 12 Feb 2022 10:11:57 +0700 Subject: [PATCH] plurals --- src/i18n/en_US.jsonc | 14 ++++---------- src/renderer/index.js | 23 +++++++++++++++-------- src/renderer/views/main.ejs | 1 + 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/i18n/en_US.jsonc b/src/i18n/en_US.jsonc index 76216893..07c72a2e 100644 --- a/src/i18n/en_US.jsonc +++ b/src/i18n/en_US.jsonc @@ -124,16 +124,10 @@ "term.contributors": "Contributors", "term.equalizer": "Equalizer", "term.reset": "Reset", - "term.track": [ - { - "value": 1, - "text": "track" - }, - { - "value": 2, - "text": "tracks" - } - ], + "term.track": { + "one" : "track", + "other" : "tracks" + }, "term.tracks": "tracks", // Assume x amount of tracks. e.g. 50 tracks "term.videos": "Videos", "term.menu": "Menu", diff --git a/src/renderer/index.js b/src/renderer/index.js index 7ed2b57c..d2475642 100644 --- a/src/renderer/index.js +++ b/src/renderer/index.js @@ -324,13 +324,17 @@ const app = new Vue({ }, getLz(message, options = {}) { if (this.lz[message]) { - if(options["plural"]) { - let closest = this.lz[message].reduce(function(prev, curr) { - return (Math.abs(curr.value - options["plural"]) < Math.abs(prev.value - options["plural"]) ? curr : prev); - }); - return closest.text; - }else if(typeof this.lz[message] === "object") { - return this.lz[message][0].text; + if(options["count"] ) { + if (typeof this.lz[message] === "object"){ + let type = window.fastPluralRules.getPluralFormNameForCardinalByLocale(this.cfg.general.language.replace("_","-"),options["count"]); + return this.lz[message][type] ?? ((this.lz[message])[Object.keys(this.lz[message])[0]] ?? this.lz[message]) + } else { + // fallback English plural forms ( old i18n ) + if (options["count"] > 1) { + return this.lz[message+ "s"] ?? this.lz[message]} else { return this.lz[message]} + } + } else if(typeof this.lz[message] === "object") { + return (this.lz[message])[Object.keys(this.lz[message])[0]] } return this.lz[message] } else { @@ -2149,7 +2153,10 @@ const app = new Vue({ let hours = Math.floor(time / 3600) let mins = Math.floor(time / 60) % 60 let secs = time % 60 - return app.showingPlaylist.relationships.tracks.data.length + " " + app.getLz('term.tracks') + ", " + ((hours > 0) ? (hours + (" " + ((hours > 1) ? app.getLz('term.time.hours') + ", " : app.getLz('term.time.hour') + ", "))) : "") + ((mins > 0) ? (mins + ((mins > 1) ? " " + app.getLz('term.time.minutes') + ", " : " " + app.getLz('term.time.minute') + ", ")) : "") + secs + ((secs > 1) ? " " + app.getLz('term.time.seconds') + "." : " " + app.getLz('term.time.second') + "."); + return app.showingPlaylist.relationships.tracks.data.length + " " + app.getLz('term.track', options = {count : app.showingPlaylist.relationships.tracks.data.length}) + ", " + + ((hours > 0) ? (hours + (" " + (app.getLz('term.time.hour', options = {count : hours}) + ", "))) : "") + + ((mins > 0) ? (mins + (" " + app.getLz('term.time.minute', options = {count : mins}) + ", ")) : "") + + secs + (" " + app.getLz('term.time.second', options = {count : secs}) + "."); } else return "" } catch (err) { return "" diff --git a/src/renderer/views/main.ejs b/src/renderer/views/main.ejs index 55b4403d..3097a196 100644 --- a/src/renderer/views/main.ejs +++ b/src/renderer/views/main.ejs @@ -72,6 +72,7 @@ document.write(unescape("%3Cscript src='https://js-cdn.music.apple.com/musickit/v2/amp/musickit.js' type='text/javascript'%3E%3C/script%3E")); } +