From 4e23f4953c7c3720bb673467673939a362c48cfd Mon Sep 17 00:00:00 2001 From: Alessandro Cocco Date: Thu, 21 Apr 2022 22:06:02 +0200 Subject: [PATCH] [locale] Add dowAll(), improve dow() --- apps/locale/ChangeLog | 1 + apps/locale/README.md | 23 ++++++++++++++++------- apps/locale/locale.html | 3 ++- apps/locale/metadata.json | 2 +- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/apps/locale/ChangeLog b/apps/locale/ChangeLog index d21cb1a56..39d40c8d4 100644 --- a/apps/locale/ChangeLog +++ b/apps/locale/ChangeLog @@ -19,3 +19,4 @@ 0.16: Remove global variables that used RAM Add second 'dp' argument for decimal places in distance/speed/temp (fix #1523) 0.17: Fix regression where long month names were 'undefined' (fix #1641) +0.18: Add function dowAll(), update function dow() diff --git a/apps/locale/README.md b/apps/locale/README.md index fd43c2825..99fba7945 100644 --- a/apps/locale/README.md +++ b/apps/locale/README.md @@ -1,25 +1,34 @@ -# Languages (locale) +Languages (locale) +================== Country-specific app internationalisation. This is not an app, but instead it is a library that can be used by -other applications or widgets to display messages. +other applications or widgets to provide locale-friendly -## Usage +- Dates +- Time (12h/24h) +- Days of the Week +- Months +- Currency values +- Distances/Lengths/Speed (metric/imperial) +- Temperature (°C/°F) -Some menus that pop up are translated automatically, but if you're -writing an application you can use the `locale` library to +Usage +----- + +If you're writing an application you can use the `locale` library to do all the translation for you. See https://www.espruino.com/Bangle.js+Locale for full examples. ```JS // Date to date string (long) ->require('locale').date(new Date()) +>require("locale").date(new Date()) ="Donnerstag, 02. April 2020" // Date to date string (short) ->require('locale').date(new Date(),1) +>require("locale").date(new Date(), 1) ="02.04.2020" ``` diff --git a/apps/locale/locale.html b/apps/locale/locale.html index 6eb0d94ea..41e882dfa 100644 --- a/apps/locale/locale.html +++ b/apps/locale/locale.html @@ -198,7 +198,8 @@ function getHours(d) { exports = { name: ${js(locale.lang)}, currencySym: ${js(locale.currency_symbol)}, - dow: (d,short) => ${js(locale.day + ',' + locale.abday)}.split(',')[d.getDay() + (short ? 7 : 0)], + dow: (d,short) => ${js(locale.day + ',' + locale.abday + ',' + locale.abday.split(',').map(e => e.charAt(0).toUpperCase()).join(','))}.split(',')[d.getDay() + ((short || 0) * 7)], + dowAll: (short) => ${js(locale.day + ',' + locale.abday + ',' + locale.abday.split(',').map(e => e.charAt(0).toUpperCase()).join(','))}.split(',').slice((short || 0) * 7, ((short || 0) + 1) * 7), month: (d,short) => ${js(locale.month + ',' + locale.abmonth)}.split(',')[d.getMonth() + (short ? 12 : 0)], number: (n, dec) => { if (dec == null) dec = 2; diff --git a/apps/locale/metadata.json b/apps/locale/metadata.json index 54ad64e80..cb45f0622 100644 --- a/apps/locale/metadata.json +++ b/apps/locale/metadata.json @@ -1,7 +1,7 @@ { "id": "locale", "name": "Languages", - "version": "0.17", + "version": "0.18", "description": "Translations for different countries", "icon": "locale.png", "type": "locale",