@nextcloud/l10n
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -5,2 +5,18 @@ # Changelog | ||
## 2.2.0 - 2023-06-26 | ||
[Full Changelog](https://github.com/nextcloud/nextcloud-l10n/compare/v2.1.0...v2.2.0) | ||
### Added | ||
- `isRTL` was added to check whether a given, or the current, language is read right-to-left [\#639](https://github.com/nextcloud/nextcloud-l10n/pull/639) ([susnux](https://github.com/susnux)) | ||
### Fixed | ||
- Add typings to the package exports to fix build for Typescript projects using `node16` or `nodenext` module resolution [\#633](https://github.com/nextcloud/nextcloud-l10n/pull/633) ([susnux](https://github.com/susnux)) | ||
- Update exported `NextcloudWindowWithRegistry` type for Nextcloud 27 [\#640](https://github.com/nextcloud/nextcloud-l10n/pull/640) ([susnux](https://github.com/susnux)) | ||
- Harden `loadTranslations` by handling edge cases where invalid data is retrieved [\#644](https://github.com/nextcloud/nextcloud-l10n/pull/644) ([susnux](https://github.com/susnux)) | ||
### Changed | ||
- Update node engines to next LTS (Node 20 + NPM 9) | ||
- Dependency updates | ||
## 2.1.0 - 2023-02-25 | ||
@@ -7,0 +23,0 @@ |
@@ -9,2 +9,5 @@ 'use strict'; | ||
/** | ||
* Returns the user's locale | ||
*/ | ||
/** | ||
* Returns the user's language | ||
@@ -11,0 +14,0 @@ */ |
@@ -15,3 +15,4 @@ /** | ||
export type { Translations } from './registry'; | ||
export * from './date'; | ||
export * from './locale'; | ||
export * from './translation'; | ||
export * from './date'; |
@@ -9,2 +9,172 @@ 'use strict'; | ||
/** | ||
* Get the first day of the week | ||
* | ||
* @return {number} | ||
*/ | ||
function getFirstDay() { | ||
if (typeof window.firstDay === 'undefined') { | ||
console.warn('No firstDay found'); | ||
return 1; | ||
} | ||
return window.firstDay; | ||
} | ||
/** | ||
* Get a list of day names (full names) | ||
* | ||
* @return {string[]} | ||
*/ | ||
function getDayNames() { | ||
if (typeof window.dayNames === 'undefined') { | ||
console.warn('No dayNames found'); | ||
return [ | ||
'Sunday', | ||
'Monday', | ||
'Tuesday', | ||
'Wednesday', | ||
'Thursday', | ||
'Friday', | ||
'Saturday', | ||
]; | ||
} | ||
return window.dayNames; | ||
} | ||
/** | ||
* Get a list of day names (short names) | ||
* | ||
* @return {string[]} | ||
*/ | ||
function getDayNamesShort() { | ||
if (typeof window.dayNamesShort === 'undefined') { | ||
console.warn('No dayNamesShort found'); | ||
return ['Sun.', 'Mon.', 'Tue.', 'Wed.', 'Thu.', 'Fri.', 'Sat.']; | ||
} | ||
return window.dayNamesShort; | ||
} | ||
/** | ||
* Get a list of day names (minified names) | ||
* | ||
* @return {string[]} | ||
*/ | ||
function getDayNamesMin() { | ||
if (typeof window.dayNamesMin === 'undefined') { | ||
console.warn('No dayNamesMin found'); | ||
return ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']; | ||
} | ||
return window.dayNamesMin; | ||
} | ||
/** | ||
* Get a list of month names (full names) | ||
* | ||
* @return {string[]} | ||
*/ | ||
function getMonthNames() { | ||
if (typeof window.monthNames === 'undefined') { | ||
console.warn('No monthNames found'); | ||
return [ | ||
'January', | ||
'February', | ||
'March', | ||
'April', | ||
'May', | ||
'June', | ||
'July', | ||
'August', | ||
'September', | ||
'October', | ||
'November', | ||
'December', | ||
]; | ||
} | ||
return window.monthNames; | ||
} | ||
/** | ||
* Get a list of month names (short names) | ||
* | ||
* @return {string[]} | ||
*/ | ||
function getMonthNamesShort() { | ||
if (typeof window.monthNamesShort === 'undefined') { | ||
console.warn('No monthNamesShort found'); | ||
return [ | ||
'Jan.', | ||
'Feb.', | ||
'Mar.', | ||
'Apr.', | ||
'May.', | ||
'Jun.', | ||
'Jul.', | ||
'Aug.', | ||
'Sep.', | ||
'Oct.', | ||
'Nov.', | ||
'Dec.', | ||
]; | ||
} | ||
return window.monthNamesShort; | ||
} | ||
/** | ||
* Returns the user's locale | ||
*/ | ||
function getLocale() { | ||
return document.documentElement.dataset.locale || 'en'; | ||
} | ||
/** | ||
* Returns user's locale in canonical form | ||
* E.g. `en-US` instead of `en_US` | ||
*/ | ||
function getCanonicalLocale() { | ||
return getLocale().replace(/_/g, '-'); | ||
} | ||
/** | ||
* Returns the user's language | ||
*/ | ||
function getLanguage() { | ||
return document.documentElement.lang || 'en'; | ||
} | ||
/** | ||
* Check whether the current, or a given, language is read right-to-left | ||
* | ||
* @param language Language code to check, defaults to current language | ||
*/ | ||
function isRTL(language) { | ||
const languageCode = language || getLanguage(); | ||
// Source: https://meta.wikimedia.org/wiki/Template:List_of_language_names_ordered_by_code | ||
const rtlLanguages = [ | ||
/* eslint-disable no-multi-spaces */ | ||
'ae', | ||
'ar', | ||
'arc', | ||
'arz', | ||
'bcc', | ||
'bqi', | ||
'ckb', | ||
'dv', | ||
'fa', | ||
'glk', | ||
'ha', | ||
'he', | ||
'khw', | ||
'ks', | ||
'ku', | ||
'mzn', | ||
'nqo', | ||
'pnb', | ||
'ps', | ||
'sd', | ||
'ug', | ||
'ur', | ||
'uzs', | ||
'yi', // 'ייִדיש', Yiddish | ||
/* eslint-enable no-multi-spaces */ | ||
]; | ||
// special case for Uzbek Afghan | ||
if ((language || getCanonicalLocale()).startsWith('uz-AF')) { | ||
return true; | ||
} | ||
return rtlLanguages.includes(languageCode); | ||
} | ||
/// <reference types="@nextcloud/typings" /> | ||
/** | ||
* Check if translations and plural function are set for given app | ||
@@ -61,21 +231,2 @@ * | ||
/** | ||
* Returns the user's locale | ||
*/ | ||
function getLocale() { | ||
return document.documentElement.dataset.locale || 'en'; | ||
} | ||
/** | ||
* Returns user's locale in canonical form | ||
* E.g. `en-US` instead of `en_US` | ||
*/ | ||
function getCanonicalLocale() { | ||
return getLocale().replace(/_/g, '-'); | ||
} | ||
/** | ||
* Returns the user's language | ||
*/ | ||
function getLanguage() { | ||
return document.documentElement.lang || 'en'; | ||
} | ||
/** | ||
* Translate a string | ||
@@ -175,7 +326,11 @@ * | ||
if (request.status >= 200 && request.status < 300) { | ||
const bundle = JSON.parse(request.responseText); | ||
if (bundle === null || bundle === void 0 ? void 0 : bundle.translations) | ||
resolve(bundle); | ||
else | ||
reject(new Error('Invalid content of translation bundle')); | ||
try { | ||
const bundle = JSON.parse(request.responseText); | ||
if (typeof bundle.translations === 'object') | ||
resolve(bundle); | ||
} | ||
catch (error) { | ||
// error is probably a SyntaxError due to invalid response text, this is handled by next line | ||
} | ||
reject(new Error('Invalid content of translation bundle')); | ||
} | ||
@@ -406,110 +561,2 @@ else { | ||
/// <reference types="@nextcloud/typings" /> | ||
/** | ||
* Get the first day of the week | ||
* | ||
* @return {number} | ||
*/ | ||
function getFirstDay() { | ||
if (typeof window.firstDay === 'undefined') { | ||
console.warn('No firstDay found'); | ||
return 1; | ||
} | ||
return window.firstDay; | ||
} | ||
/** | ||
* Get a list of day names (full names) | ||
* | ||
* @return {string[]} | ||
*/ | ||
function getDayNames() { | ||
if (typeof window.dayNames === 'undefined') { | ||
console.warn('No dayNames found'); | ||
return [ | ||
'Sunday', | ||
'Monday', | ||
'Tuesday', | ||
'Wednesday', | ||
'Thursday', | ||
'Friday', | ||
'Saturday', | ||
]; | ||
} | ||
return window.dayNames; | ||
} | ||
/** | ||
* Get a list of day names (short names) | ||
* | ||
* @return {string[]} | ||
*/ | ||
function getDayNamesShort() { | ||
if (typeof window.dayNamesShort === 'undefined') { | ||
console.warn('No dayNamesShort found'); | ||
return ['Sun.', 'Mon.', 'Tue.', 'Wed.', 'Thu.', 'Fri.', 'Sat.']; | ||
} | ||
return window.dayNamesShort; | ||
} | ||
/** | ||
* Get a list of day names (minified names) | ||
* | ||
* @return {string[]} | ||
*/ | ||
function getDayNamesMin() { | ||
if (typeof window.dayNamesMin === 'undefined') { | ||
console.warn('No dayNamesMin found'); | ||
return ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']; | ||
} | ||
return window.dayNamesMin; | ||
} | ||
/** | ||
* Get a list of month names (full names) | ||
* | ||
* @return {string[]} | ||
*/ | ||
function getMonthNames() { | ||
if (typeof window.monthNames === 'undefined') { | ||
console.warn('No monthNames found'); | ||
return [ | ||
'January', | ||
'February', | ||
'March', | ||
'April', | ||
'May', | ||
'June', | ||
'July', | ||
'August', | ||
'September', | ||
'October', | ||
'November', | ||
'December', | ||
]; | ||
} | ||
return window.monthNames; | ||
} | ||
/** | ||
* Get a list of month names (short names) | ||
* | ||
* @return {string[]} | ||
*/ | ||
function getMonthNamesShort() { | ||
if (typeof window.monthNamesShort === 'undefined') { | ||
console.warn('No monthNamesShort found'); | ||
return [ | ||
'Jan.', | ||
'Feb.', | ||
'Mar.', | ||
'Apr.', | ||
'May.', | ||
'Jun.', | ||
'Jul.', | ||
'Aug.', | ||
'Sep.', | ||
'Oct.', | ||
'Nov.', | ||
'Dec.', | ||
]; | ||
} | ||
return window.monthNamesShort; | ||
} | ||
exports.getCanonicalLocale = getCanonicalLocale; | ||
@@ -525,2 +572,3 @@ exports.getDayNames = getDayNames; | ||
exports.getPlural = getPlural; | ||
exports.isRTL = isRTL; | ||
exports.loadTranslations = loadTranslations; | ||
@@ -527,0 +575,0 @@ exports.register = register; |
@@ -34,3 +34,3 @@ /// <reference types="@nextcloud/typings" /> | ||
*/ | ||
export interface NextcloudWindowWithRegistry extends Nextcloud.v25.WindowWithGlobals { | ||
export interface NextcloudWindowWithRegistry extends Nextcloud.v27.WindowWithGlobals { | ||
_oc_l10n_registry_translations?: Record<string, Translations>; | ||
@@ -37,0 +37,0 @@ _oc_l10n_registry_plural_functions?: Record<string, PluralFunction>; |
@@ -10,15 +10,2 @@ import type { Translations } from './registry'; | ||
/** | ||
* Returns the user's locale | ||
*/ | ||
export declare function getLocale(): string; | ||
/** | ||
* Returns user's locale in canonical form | ||
* E.g. `en-US` instead of `en_US` | ||
*/ | ||
export declare function getCanonicalLocale(): string; | ||
/** | ||
* Returns the user's language | ||
*/ | ||
export declare function getLanguage(): string; | ||
/** | ||
* Translate a string | ||
@@ -25,0 +12,0 @@ * |
{ | ||
"name": "@nextcloud/l10n", | ||
"version": "2.1.0", | ||
"description": "", | ||
"version": "2.2.0", | ||
"description": "Nextcloud L10n helpers for apps and libraries", | ||
"main": "dist/index.js", | ||
@@ -9,2 +9,3 @@ "types": "dist/index.d.ts", | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.mjs", | ||
@@ -14,2 +15,3 @@ "require": "./dist/index.js" | ||
"./gettext": { | ||
"types": "./dist/gettext.d.ts", | ||
"import": "./dist/gettext.mjs", | ||
@@ -28,3 +30,4 @@ "require": "./dist/gettext.js" | ||
"test": "jest --verbose", | ||
"test:watch": "jest --watchAll" | ||
"test:watch": "jest --watchAll", | ||
"test:coverage": "jest --coverage" | ||
}, | ||
@@ -42,4 +45,5 @@ "keywords": [ | ||
"dependencies": { | ||
"@nextcloud/router": "^2.0.0", | ||
"dompurify": "^2.4.1", | ||
"@nextcloud/router": "^2.1.2", | ||
"@nextcloud/typings": "^1.7.0", | ||
"dompurify": "^3.0.3", | ||
"escape-html": "^1.0.3", | ||
@@ -51,16 +55,15 @@ "node-gettext": "^3.0.0" | ||
"@nextcloud/eslint-config": "^8.2.0", | ||
"@nextcloud/typings": "^1.6.0", | ||
"@rollup/plugin-typescript": "^11.0.0", | ||
"@types/jest": "^29.2.5", | ||
"@rollup/plugin-typescript": "^11.1.1", | ||
"@types/jest": "^29.5.2", | ||
"@types/node-gettext": "^3.0", | ||
"@zamiell/typedoc-plugin-not-exported": "^0.2.0", | ||
"check-es-compat": "^2.2.0", | ||
"gettext-parser": "^6.0.0", | ||
"jest": "^29.3.1", | ||
"jest-environment-jsdom": "^29.3.1", | ||
"mock-xmlhttprequest": "^8.1.0", | ||
"rollup": "^3.9.1", | ||
"ts-jest": "^29.0.3", | ||
"tslib": "^2.4.1", | ||
"typedoc": "^0.23.23" | ||
"check-es-compat": "^3.0.0", | ||
"gettext-parser": "^7.0.0", | ||
"jest": "^29.5.0", | ||
"jest-environment-jsdom": "^29.5.0", | ||
"mock-xmlhttprequest": "^8.2.0", | ||
"rollup": "^3.25.1", | ||
"ts-jest": "^29.1.0", | ||
"tslib": "^2.5.3", | ||
"typedoc": "^0.24.8" | ||
}, | ||
@@ -71,5 +74,9 @@ "browserslist": [ | ||
"engines": { | ||
"node": "^16.0.0", | ||
"npm": "^7.0.0 || ^8.0.0" | ||
} | ||
"node": "^20.0.0", | ||
"npm": "^9.0.0" | ||
}, | ||
"files": [ | ||
"CHANGELOG.md", | ||
"dist" | ||
] | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
91056
15
14
1584
5
+ Added@nextcloud/typings@^1.7.0
+ Added@types/trusted-types@2.0.7(transitive)
+ Addeddompurify@3.2.3(transitive)
- Removeddompurify@2.5.8(transitive)
Updated@nextcloud/router@^2.1.2
Updateddompurify@^3.0.3