Sfoglia il codice sorgente

Improve i18n types and fix linting error

JC Brand 1 mese fa
parent
commit
5e2d76339a
2 ha cambiato i file con 14 aggiunte e 6 eliminazioni
  1. 7 3
      src/i18n/index.js
  2. 7 3
      src/types/i18n/index.d.ts

+ 7 - 3
src/i18n/index.js

@@ -5,7 +5,7 @@
  * @description This is the internationalization module
  */
 import Jed from 'jed';
-import { api, converse, log, u, i18n as i18nStub } from '@converse/headless';
+import { api, converse, log, i18n as i18nStub } from '@converse/headless';
 
 const { dayjs } = converse.env;
 
@@ -24,7 +24,7 @@ function isConverseLocale(preferred_locale, supported_locales) {
  * Determines which locale is supported by the user's system as well
  * as by the relevant library (e.g. converse.js or dayjs).
  * @param {string} preferred_locale
- * @param {Function} isSupportedByLibrary - Returns a boolean indicating whether
+ * @param {(locale: string) => boolean} isSupportedByLibrary - Returns a boolean indicating whether
  *   the locale is supported.
  * @returns {string}
  */
@@ -45,7 +45,7 @@ function determineLocale(preferred_locale, isSupportedByLibrary) {
 /**
  * Check whether the locale or sub locale (e.g. en-US, en) is supported.
  * @param {string} locale - The locale to check for
- * @param {Function} available - Returns a boolean indicating whether the locale is supported
+ * @param {(locale: string) => boolean} available - Returns a boolean indicating whether the locale is supported
  */
 function isLocaleAvailable(locale, available) {
     if (available(locale)) {
@@ -118,6 +118,10 @@ async function initialize() {
     }
 }
 
+/**
+ * @param {string} str
+ * @param {...(string|number)} args
+ */
 export function __(str, ...args) {
     return i18n.translate(str, args);
 }

+ 7 - 3
src/types/i18n/index.d.ts

@@ -1,4 +1,8 @@
-export function __(str: any, ...args: any[]): any;
+/**
+ * @param {string} str
+ * @param {...(string|number)} args
+ */
+export function __(str: string, ...args: (string | number)[]): any;
 /**
  * @namespace i18n
  */
@@ -14,11 +18,11 @@ import { i18n as i18nStub } from '@converse/headless';
  * Determines which locale is supported by the user's system as well
  * as by the relevant library (e.g. converse.js or dayjs).
  * @param {string} preferred_locale
- * @param {Function} isSupportedByLibrary - Returns a boolean indicating whether
+ * @param {(locale: string) => boolean} isSupportedByLibrary - Returns a boolean indicating whether
  *   the locale is supported.
  * @returns {string}
  */
-declare function determineLocale(preferred_locale: string, isSupportedByLibrary: Function): string;
+declare function determineLocale(preferred_locale: string, isSupportedByLibrary: (locale: string) => boolean): string;
 declare function getLocale(): string;
 declare function initialize(): Promise<void>;
 /**