[locale] Add dowAll(), improve dow()

master
Alessandro Cocco 2022-04-21 22:06:02 +02:00
parent b15e79457a
commit 4e23f4953c
4 changed files with 20 additions and 9 deletions

View File

@ -19,3 +19,4 @@
0.16: Remove global variables that used RAM 0.16: Remove global variables that used RAM
Add second 'dp' argument for decimal places in distance/speed/temp (fix #1523) 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.17: Fix regression where long month names were 'undefined' (fix #1641)
0.18: Add function dowAll(), update function dow()

View File

@ -1,25 +1,34 @@
# Languages (locale) Languages (locale)
==================
Country-specific app internationalisation. Country-specific app internationalisation.
This is not an app, but instead it is a library that can be used by 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 Usage
writing an application you can use the `locale` library to -----
If you're writing an application you can use the `locale` library to
do all the translation for you. do all the translation for you.
See https://www.espruino.com/Bangle.js+Locale for full examples. See https://www.espruino.com/Bangle.js+Locale for full examples.
```JS ```JS
// Date to date string (long) // Date to date string (long)
>require('locale').date(new Date()) >require("locale").date(new Date())
="Donnerstag, 02. April 2020" ="Donnerstag, 02. April 2020"
// Date to date string (short) // Date to date string (short)
>require('locale').date(new Date(),1) >require("locale").date(new Date(), 1)
="02.04.2020" ="02.04.2020"
``` ```

View File

@ -198,7 +198,8 @@ function getHours(d) {
exports = { exports = {
name: ${js(locale.lang)}, name: ${js(locale.lang)},
currencySym: ${js(locale.currency_symbol)}, 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)], month: (d,short) => ${js(locale.month + ',' + locale.abmonth)}.split(',')[d.getMonth() + (short ? 12 : 0)],
number: (n, dec) => { number: (n, dec) => {
if (dec == null) dec = 2; if (dec == null) dec = 2;

View File

@ -1,7 +1,7 @@
{ {
"id": "locale", "id": "locale",
"name": "Languages", "name": "Languages",
"version": "0.17", "version": "0.18",
"description": "Translations for different countries", "description": "Translations for different countries",
"icon": "locale.png", "icon": "locale.png",
"type": "locale", "type": "locale",