generaltranslation 8.2.13 → 8.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -1
- package/dist/{ApiError-IYfaOR30.mjs → ApiError-0DxxIHLp.mjs} +1 -1
- package/dist/{ApiError-CZ45tkW6.cjs.map → ApiError-0DxxIHLp.mjs.map} +1 -1
- package/dist/{ApiError-CZ45tkW6.cjs → ApiError-D-IBuHj6.cjs} +1 -1
- package/dist/{ApiError-IYfaOR30.mjs.map → ApiError-D-IBuHj6.cjs.map} +1 -1
- package/dist/LocaleConfig.d.ts +1 -59
- package/dist/LocaleConfig.js +1 -225
- package/dist/{base64-2fu94Klt.cjs → base64-YBGAXkqy.cjs} +74 -1
- package/dist/base64-YBGAXkqy.cjs.map +1 -0
- package/dist/{base64-DH0STixb.mjs → base64-r7YWJYWt.mjs} +51 -2
- package/dist/base64-r7YWJYWt.mjs.map +1 -0
- package/dist/core.cjs +9 -8
- package/dist/core.d.cts +1 -2
- package/dist/core.d.mts +1 -2
- package/dist/core.d.ts +1 -128
- package/dist/core.js +1 -137
- package/dist/core.mjs +2 -2
- package/dist/derive/indexVars.d.ts +1 -1
- package/dist/errors.cjs +1 -1
- package/dist/errors.mjs +1 -1
- package/dist/id/types.d.ts +1 -1
- package/dist/{id-CyiXsQrY.cjs → id-C2orn1MA.cjs} +2 -2
- package/dist/{id-CyiXsQrY.cjs.map → id-C2orn1MA.cjs.map} +1 -1
- package/dist/{id-DbD7K-HL.mjs → id-DEaFhGqX.mjs} +2 -2
- package/dist/{id-DbD7K-HL.mjs.map → id-DEaFhGqX.mjs.map} +1 -1
- package/dist/id.cjs +1 -1
- package/dist/id.d.cts +1 -1
- package/dist/id.d.mts +1 -1
- package/dist/id.mjs +1 -1
- package/dist/index.cjs +431 -396
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -242
- package/dist/index.d.mts +4 -242
- package/dist/index.d.ts +5 -238
- package/dist/index.js +3 -322
- package/dist/index.mjs +278 -363
- package/dist/index.mjs.map +1 -1
- package/dist/internal.cjs +8 -6
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +37 -6
- package/dist/internal.d.mts +37 -6
- package/dist/internal.d.ts +2 -0
- package/dist/internal.js +1 -0
- package/dist/internal.mjs +5 -5
- package/dist/internal.mjs.map +1 -1
- package/dist/{isVariable-B08mggBy.cjs → isVariable-Ba1gLXdB.cjs} +1 -1
- package/dist/{isVariable-B08mggBy.cjs.map → isVariable-Ba1gLXdB.cjs.map} +1 -1
- package/dist/{isVariable-CYsKFHvR.mjs → isVariable-fAKEB7gF.mjs} +1 -1
- package/dist/{isVariable-CYsKFHvR.mjs.map → isVariable-fAKEB7gF.mjs.map} +1 -1
- package/dist/locales/getPluralForm.js +2 -2
- package/dist/logging/diagnostics.d.ts +18 -0
- package/dist/logging/diagnostics.js +64 -0
- package/dist/logging/errors.d.ts +1 -1
- package/dist/logging/errors.js +64 -11
- package/dist/logging/logger.d.ts +0 -3
- package/dist/logging/logger.js +0 -3
- package/dist/{types-AHtYZIP-.d.mts → types-CdRgQtET.d.cts} +6 -106
- package/dist/{types-Bf8_Apq_.d.cts → types-Db2Dn3oN.d.mts} +6 -106
- package/dist/types-dir/api/enqueueEntries.d.ts +1 -1
- package/dist/types-dir/api/enqueueFiles.d.ts +1 -1
- package/dist/types-dir/api/fetchTranslations.d.ts +1 -1
- package/dist/types-dir/api/file.d.ts +1 -1
- package/dist/types-dir/api/translate.d.ts +1 -1
- package/dist/types-dir/api/uploadFiles.d.ts +1 -1
- package/dist/types.cjs +7 -16
- package/dist/types.d.cts +2 -2
- package/dist/types.d.mts +2 -2
- package/dist/types.d.ts +10 -13
- package/dist/types.js +1 -2
- package/dist/types.mjs +1 -15
- package/package.json +3 -2
- package/dist/IntlCache-CAW8tKhd.cjs +0 -212
- package/dist/IntlCache-CAW8tKhd.cjs.map +0 -1
- package/dist/IntlCache-WZk0rKvj.mjs +0 -195
- package/dist/IntlCache-WZk0rKvj.mjs.map +0 -1
- package/dist/base64-2fu94Klt.cjs.map +0 -1
- package/dist/base64-DH0STixb.mjs.map +0 -1
- package/dist/cache/IntlCache.d.ts +0 -26
- package/dist/cache/IntlCache.js +0 -84
- package/dist/cache/types.d.ts +0 -32
- package/dist/cache/types.js +0 -1
- package/dist/core-7RP541eY.cjs +0 -1677
- package/dist/core-7RP541eY.cjs.map +0 -1
- package/dist/core-I9pWGafA.d.mts +0 -209
- package/dist/core-TLJoDpJP.d.cts +0 -209
- package/dist/core-isLphYAZ.mjs +0 -1498
- package/dist/core-isLphYAZ.mjs.map +0 -1
- package/dist/errors/formattingErrors.d.ts +0 -1
- package/dist/errors/formattingErrors.js +0 -3
- package/dist/formatting/custom-formats/CutoffFormat/CutoffFormat.d.ts +0 -59
- package/dist/formatting/custom-formats/CutoffFormat/CutoffFormat.js +0 -147
- package/dist/formatting/custom-formats/CutoffFormat/constants.d.ts +0 -4
- package/dist/formatting/custom-formats/CutoffFormat/constants.js +0 -30
- package/dist/formatting/custom-formats/CutoffFormat/types.d.ts +0 -48
- package/dist/formatting/custom-formats/CutoffFormat/types.js +0 -2
- package/dist/formatting/format.d.ts +0 -1
- package/dist/formatting/format.js +0 -257
- package/dist/locales/customLocaleMapping.d.ts +0 -11
- package/dist/locales/customLocaleMapping.js +0 -23
- package/dist/locales/determineLocale.d.ts +0 -1
- package/dist/locales/determineLocale.js +0 -72
- package/dist/locales/getLocaleDirection.d.ts +0 -1
- package/dist/locales/getLocaleDirection.js +0 -89
- package/dist/locales/getLocaleEmoji.d.ts +0 -2
- package/dist/locales/getLocaleEmoji.js +0 -319
- package/dist/locales/getLocaleName.d.ts +0 -1
- package/dist/locales/getLocaleName.js +0 -45
- package/dist/locales/getLocaleProperties.d.ts +0 -32
- package/dist/locales/getLocaleProperties.js +0 -220
- package/dist/locales/getRegionProperties.d.ts +0 -7
- package/dist/locales/getRegionProperties.js +0 -61
- package/dist/locales/isSameDialect.d.ts +0 -1
- package/dist/locales/isSameDialect.js +0 -41
- package/dist/locales/isSameLanguage.d.ts +0 -1
- package/dist/locales/isSameLanguage.js +0 -20
- package/dist/locales/isSupersetLocale.d.ts +0 -1
- package/dist/locales/isSupersetLocale.js +0 -22
- package/dist/locales/isValidLocale.d.ts +0 -1
- package/dist/locales/isValidLocale.js +0 -75
- package/dist/locales/requiresTranslation.d.ts +0 -1
- package/dist/locales/requiresTranslation.js +0 -32
- package/dist/locales/resolveAliasLocale.d.ts +0 -8
- package/dist/locales/resolveAliasLocale.js +0 -21
- package/dist/locales/resolveCanonicalLocale.d.ts +0 -8
- package/dist/locales/resolveCanonicalLocale.js +0 -13
- package/dist/logging/warnings.d.ts +0 -2
- package/dist/logging/warnings.js +0 -2
- package/dist/types-dir/jsx/content.d.ts +0 -61
- package/dist/types-dir/jsx/content.js +0 -11
- package/dist/types-dir/jsx/variables.d.ts +0 -9
- package/dist/types-dir/jsx/variables.js +0 -1
- package/dist/types.cjs.map +0 -1
- package/dist/types.mjs.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { LocaleProperties } from '
|
|
1
|
+
import { LocaleConfig } from '@generaltranslation/format';
|
|
2
|
+
import type { CustomMapping, CustomRegionMapping, CutoffFormatOptions, FormatVariables, LocaleProperties, StringFormat } from '@generaltranslation/format/types';
|
|
3
|
+
import { TranslateManyResult, TranslationError, TranslationResult, EnqueueFilesResult, CheckFileTranslationsOptions, DownloadFileBatchOptions, DownloadFileBatchResult, DownloadFileOptions, TranslateManyEntry } from './types';
|
|
3
4
|
import { SetupProjectResult, SetupProjectOptions } from './translate/setupProject';
|
|
4
5
|
import { EnqueueOptions } from './translate/enqueueFiles';
|
|
5
6
|
import { CreateTagOptions, CreateTagResult } from './translate/createTag';
|
|
6
7
|
import { FileQuery, FileQueryResult } from './types-dir/api/checkFileTranslations';
|
|
7
8
|
import { SubmitUserEditDiffsPayload } from './translate/submitUserEditDiffs';
|
|
8
|
-
import { CustomRegionMapping } from './locales/getRegionProperties';
|
|
9
9
|
import { FileUpload, UploadFilesOptions, UploadFilesResponse } from './types-dir/api/uploadFiles';
|
|
10
10
|
import { ProjectData } from './types-dir/api/project';
|
|
11
11
|
import { DownloadFileBatchRequest } from './types-dir/api/downloadFileBatch';
|
|
@@ -19,12 +19,9 @@ import type { FileReference, FileReferenceIds } from './types-dir/api/file';
|
|
|
19
19
|
import { type MoveMapping, type ProcessMovesResponse, type ProcessMovesOptions } from './translate/processFileMoves';
|
|
20
20
|
import { type GetOrphanedFilesResult } from './translate/getOrphanedFiles';
|
|
21
21
|
import { type PublishFileEntry, type PublishFilesResult } from './translate/publishFiles';
|
|
22
|
-
import { CutoffFormatOptions } from './formatting/custom-formats/CutoffFormat/types';
|
|
23
22
|
import { TranslateOptions } from './types-dir/api/entry';
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export { LocaleConfig, type LocaleConfigConstructorParams, } from './LocaleConfig';
|
|
27
|
-
export { formatCutoff, formatMessage, isValidLocale, resolveCanonicalLocale, standardizeLocale, } from './core';
|
|
23
|
+
export { LocaleConfig, type LocaleConfigConstructorParams, } from '@generaltranslation/format';
|
|
24
|
+
export { determineLocale, formatCurrency, formatCutoff, formatDateTime, formatList, formatListToParts, formatMessage, formatNum, formatRelativeTime, formatRelativeTimeFromDate, getLocaleDirection, getLocaleEmoji, getLocaleName, getLocaleProperties, getRegionProperties, isSameDialect, isSameLanguage, isSupersetLocale, isValidLocale, requiresTranslation, resolveAliasLocale, resolveCanonicalLocale, standardizeLocale, } from '@generaltranslation/format';
|
|
28
25
|
/**
|
|
29
26
|
* Type representing the constructor parameters for the GT class.
|
|
30
27
|
* @typedef {Object} GTConstructorParams
|
|
@@ -786,234 +783,4 @@ export declare class GT {
|
|
|
786
783
|
*/
|
|
787
784
|
isSupersetLocale(superLocale: string, subLocale: string): boolean;
|
|
788
785
|
}
|
|
789
|
-
/**
|
|
790
|
-
* Formats a number according to the specified locales and options.
|
|
791
|
-
* @param {Object} params - The parameters for the number formatting.
|
|
792
|
-
* @param {number} params.value - The number to format.
|
|
793
|
-
* @param {Intl.NumberFormatOptions} [params.options] - Additional options for number formatting.
|
|
794
|
-
* @param {string | string[]} [params.options.locales] - The locales to use for formatting.
|
|
795
|
-
* @returns {string} The formatted number.
|
|
796
|
-
*/
|
|
797
|
-
export declare function formatNum(number: number, options: {
|
|
798
|
-
locales: string | string[];
|
|
799
|
-
} & Intl.NumberFormatOptions): string;
|
|
800
|
-
/**
|
|
801
|
-
* Formats a date according to the specified languages and options.
|
|
802
|
-
* @param {Object} params - The parameters for the date formatting.
|
|
803
|
-
* @param {Date} params.value - The date to format.
|
|
804
|
-
* @param {Intl.DateTimeFormatOptions} [params.options] - Additional options for date formatting.
|
|
805
|
-
* @param {string | string[]} [params.options.locales] - The languages to use for formatting.
|
|
806
|
-
* @returns {string} The formatted date.
|
|
807
|
-
*/
|
|
808
|
-
export declare function formatDateTime(date: Date, options?: {
|
|
809
|
-
locales?: string | string[];
|
|
810
|
-
} & Intl.DateTimeFormatOptions): string;
|
|
811
|
-
/**
|
|
812
|
-
* Formats a currency value according to the specified languages, currency, and options.
|
|
813
|
-
* @param {Object} params - The parameters for the currency formatting.
|
|
814
|
-
* @param {number} params.value - The currency value to format.
|
|
815
|
-
* @param {string} params.currency - The currency code (e.g., 'USD').
|
|
816
|
-
* @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for currency formatting.
|
|
817
|
-
* @param {string | string[]} [params.options.locales] - The locale codes to use for formatting.
|
|
818
|
-
* @returns {string} The formatted currency value.
|
|
819
|
-
*/
|
|
820
|
-
export declare function formatCurrency(value: number, currency: string, options: {
|
|
821
|
-
locales: string | string[];
|
|
822
|
-
} & Intl.NumberFormatOptions): string;
|
|
823
|
-
/**
|
|
824
|
-
* Formats a list of items according to the specified locales and options.
|
|
825
|
-
* @param {Object} params - The parameters for the list formatting.
|
|
826
|
-
* @param {Array<string | number>} params.value - The list of items to format.
|
|
827
|
-
* @param {Intl.ListFormatOptions} [params.options={}] - Additional options for list formatting.
|
|
828
|
-
* @param {string | string[]} [params.options.locales] - The locales to use for formatting.
|
|
829
|
-
* @returns {string} The formatted list.
|
|
830
|
-
*/
|
|
831
|
-
export declare function formatList(array: Array<string | number>, options: {
|
|
832
|
-
locales: string | string[];
|
|
833
|
-
} & Intl.ListFormatOptions): string;
|
|
834
|
-
/**
|
|
835
|
-
* Formats a list of items according to the specified locales and options.
|
|
836
|
-
* @param {Array<T>} array - The list of items to format.
|
|
837
|
-
* @param {Object} [options] - Additional options for list formatting.
|
|
838
|
-
* @param {string | string[]} [options.locales] - The locales to use for formatting.
|
|
839
|
-
* @param {Intl.ListFormatOptions} [options] - Additional Intl.ListFormat options.
|
|
840
|
-
* @returns {Array<T | string>} The formatted list parts.
|
|
841
|
-
*/
|
|
842
|
-
export declare function formatListToParts<T>(array: Array<T>, options?: {
|
|
843
|
-
locales?: string | string[];
|
|
844
|
-
} & Intl.ListFormatOptions): Array<T | string>;
|
|
845
|
-
/**
|
|
846
|
-
* Formats a relative time value according to the specified locales and options.
|
|
847
|
-
* @param {Object} params - The parameters for the relative time formatting.
|
|
848
|
-
* @param {number} params.value - The relative time value to format.
|
|
849
|
-
* @param {Intl.RelativeTimeFormatUnit} params.unit - The unit of time (e.g., 'second', 'minute', 'hour', 'day', 'week', 'month', 'year').
|
|
850
|
-
* @param {Intl.RelativeTimeFormatOptions} [params.options={}] - Additional options for relative time formatting.
|
|
851
|
-
* @param {string | string[]} [params.options.locales] - The locales to use for formatting.
|
|
852
|
-
* @returns {string} The formatted relative time string.
|
|
853
|
-
*/
|
|
854
|
-
export declare function formatRelativeTime(value: number, unit: Intl.RelativeTimeFormatUnit, options: {
|
|
855
|
-
locales: string | string[];
|
|
856
|
-
} & Omit<Intl.RelativeTimeFormatOptions, 'locales'>): string;
|
|
857
|
-
/**
|
|
858
|
-
* Formats a relative time string from a Date, automatically selecting the best unit.
|
|
859
|
-
* @param {Date} date - The date to format relative to now.
|
|
860
|
-
* @param {Object} options - Formatting options.
|
|
861
|
-
* @param {string | string[]} options.locales - The locales to use for formatting.
|
|
862
|
-
* @param {Intl.RelativeTimeFormatOptions} [options] - Additional Intl.RelativeTimeFormat options.
|
|
863
|
-
* @returns {string} The formatted relative time string (e.g., "2 hours ago", "in 3 days").
|
|
864
|
-
*/
|
|
865
|
-
export declare function formatRelativeTimeFromDate(date: Date, options: {
|
|
866
|
-
locales: string | string[];
|
|
867
|
-
baseDate?: Date;
|
|
868
|
-
} & Omit<Intl.RelativeTimeFormatOptions, 'locales'>): string;
|
|
869
|
-
/**
|
|
870
|
-
* Retrieves the display name of locale code using Intl.DisplayNames.
|
|
871
|
-
*
|
|
872
|
-
* @param {string} locale - A BCP-47 locale code.
|
|
873
|
-
* @param {string} [defaultLocale] - The default locale to use for formatting.
|
|
874
|
-
* @param {CustomMapping} [customMapping] - A custom mapping of locale codes to their names.
|
|
875
|
-
* @returns {string} The display name corresponding to the code.
|
|
876
|
-
*/
|
|
877
|
-
export declare function getLocaleName(locale: string, defaultLocale?: string, customMapping?: CustomMapping): string;
|
|
878
|
-
/**
|
|
879
|
-
* Retrieves an emoji based on a given locale code, taking into account region, language, and specific exceptions.
|
|
880
|
-
*
|
|
881
|
-
* This function uses the locale's region (if present) to select an emoji or falls back on default emojis for certain languages.
|
|
882
|
-
*
|
|
883
|
-
* @param locale - A string representing the locale code (e.g., 'en-US', 'fr-CA').
|
|
884
|
-
* @param {CustomMapping} [customMapping] - A custom mapping of locale codes to their names.
|
|
885
|
-
* @returns The emoji representing the locale or its region, or a default emoji if no specific match is found.
|
|
886
|
-
*/
|
|
887
|
-
export declare function getLocaleEmoji(locale: string, customMapping?: CustomMapping): string;
|
|
888
|
-
/**
|
|
889
|
-
* Generates linguistic details for a given locale code.
|
|
890
|
-
*
|
|
891
|
-
* This function returns information about the locale,
|
|
892
|
-
* script, and region of a given language code both in a standard form and in a maximized form (with likely script and region).
|
|
893
|
-
* The function provides these names in both your default language and native forms, and an associated emoji.
|
|
894
|
-
*
|
|
895
|
-
* @param {string} locale - The locale code to get properties for (e.g., "de-AT").
|
|
896
|
-
* @param {string} [defaultLocale] - The default locale to use for formatting.
|
|
897
|
-
* @param {CustomMapping} [customMapping] - A custom mapping of locale codes to their names.
|
|
898
|
-
* @returns {LocaleProperties} - An object containing detailed information about the locale.
|
|
899
|
-
*
|
|
900
|
-
* @property {string} code - The full locale code, e.g., "de-AT".
|
|
901
|
-
* @property {string} name - Language name in the default display language, e.g., "Austrian German".
|
|
902
|
-
* @property {string} nativeName - Language name in the locale's native language, e.g., "Österreichisches Deutsch".
|
|
903
|
-
* @property {string} languageCode - The base language code, e.g., "de".
|
|
904
|
-
* @property {string} languageName - The language name in the default display language, e.g., "German".
|
|
905
|
-
* @property {string} nativeLanguageName - The language name in the native language, e.g., "Deutsch".
|
|
906
|
-
* @property {string} nameWithRegionCode - Language name with region in the default language, e.g., "German (AT)".
|
|
907
|
-
* @property {string} nativeNameWithRegionCode - Language name with region in the native language, e.g., "Deutsch (AT)".
|
|
908
|
-
* @property {string} regionCode - The region code from maximization, e.g., "AT".
|
|
909
|
-
* @property {string} regionName - The region name in the default display language, e.g., "Austria".
|
|
910
|
-
* @property {string} nativeRegionName - The region name in the native language, e.g., "Österreich".
|
|
911
|
-
* @property {string} scriptCode - The script code from maximization, e.g., "Latn".
|
|
912
|
-
* @property {string} scriptName - The script name in the default display language, e.g., "Latin".
|
|
913
|
-
* @property {string} nativeScriptName - The script name in the native language, e.g., "Lateinisch".
|
|
914
|
-
* @property {string} maximizedCode - The maximized locale code, e.g., "de-Latn-AT".
|
|
915
|
-
* @property {string} maximizedName - Maximized locale name with likely script in the default language, e.g., "Austrian German (Latin)".
|
|
916
|
-
* @property {string} nativeMaximizedName - Maximized locale name in the native language, e.g., "Österreichisches Deutsch (Lateinisch)".
|
|
917
|
-
* @property {string} minimizedCode - Minimized locale code, e.g., "de-AT" (or "de" for "de-DE").
|
|
918
|
-
* @property {string} minimizedName - Minimized language name in the default language, e.g., "Austrian German".
|
|
919
|
-
* @property {string} nativeMinimizedName - Minimized language name in the native language, e.g., "Österreichisches Deutsch".
|
|
920
|
-
* @property {string} emoji - The emoji associated with the locale's region, if applicable.
|
|
921
|
-
*/
|
|
922
|
-
export declare function getLocaleProperties(locale: string, defaultLocale?: string, customMapping?: CustomMapping): LocaleProperties;
|
|
923
|
-
/**
|
|
924
|
-
* Retrieves multiple properties for a given region code, including:
|
|
925
|
-
* - `code`: the original region code
|
|
926
|
-
* - `name`: the localized display name
|
|
927
|
-
* - `emoji`: the associated flag or symbol
|
|
928
|
-
*
|
|
929
|
-
* Behavior:
|
|
930
|
-
* - Accepts ISO 3166-1 alpha-2 or UN M.49 region codes (e.g., `"US"`, `"FR"`, `"419"`).
|
|
931
|
-
* - If `customMapping` contains a `name` or `emoji` for the region, those override the default values.
|
|
932
|
-
* - Otherwise, uses `Intl.DisplayNames` to get the localized region name in the given `defaultLocale`,
|
|
933
|
-
* falling back to `libraryDefaultLocale`.
|
|
934
|
-
* - Falls back to the region code as `name` if display name resolution fails.
|
|
935
|
-
* - Falls back to `defaultEmoji` if no emoji mapping is found in `emojis` or `customMapping`.
|
|
936
|
-
*
|
|
937
|
-
* @param {string} region - The region code to look up (e.g., `"US"`, `"GB"`, `"DE"`).
|
|
938
|
-
* @param {string} [defaultLocale=libraryDefaultLocale] - The locale to use when localizing the region name.
|
|
939
|
-
* @param {CustomRegionMapping} [customMapping] - Optional mapping of region codes to custom names and/or emojis.
|
|
940
|
-
* @returns {{ code: string, name: string, emoji: string }} An object containing:
|
|
941
|
-
* - `code`: the input region code
|
|
942
|
-
* - `name`: the localized or custom region name
|
|
943
|
-
* - `emoji`: the matching emoji flag or symbol
|
|
944
|
-
*
|
|
945
|
-
* @example
|
|
946
|
-
* getRegionProperties('US', 'en');
|
|
947
|
-
* // => { code: 'US', name: 'United States', emoji: '🇺🇸' }
|
|
948
|
-
*
|
|
949
|
-
* @example
|
|
950
|
-
* getRegionProperties('US', 'fr');
|
|
951
|
-
* // => { code: 'US', name: 'États-Unis', emoji: '🇺🇸' }
|
|
952
|
-
*
|
|
953
|
-
* @example
|
|
954
|
-
* getRegionProperties('US', 'en', { US: { name: 'USA', emoji: '🗽' } });
|
|
955
|
-
* // => { code: 'US', name: 'USA', emoji: '🗽' }
|
|
956
|
-
*/
|
|
957
|
-
export declare function getRegionProperties(region: string, defaultLocale?: string, customMapping?: CustomRegionMapping): {
|
|
958
|
-
code: string;
|
|
959
|
-
name: string;
|
|
960
|
-
emoji: string;
|
|
961
|
-
};
|
|
962
|
-
/**
|
|
963
|
-
* Determines whether a translation is required based on the source and target locales.
|
|
964
|
-
*
|
|
965
|
-
* - If the target locale is not specified, the function returns `false`, as translation is not needed.
|
|
966
|
-
* - If the source and target locale are the same, returns `false`, indicating that no translation is necessary.
|
|
967
|
-
* - If the `approvedLocales` array is provided, and the target locale is not within that array, the function also returns `false`.
|
|
968
|
-
* - Otherwise, it returns `true`, meaning that a translation is required.
|
|
969
|
-
*
|
|
970
|
-
* @param {string} sourceLocale - The locale code for the original content (BCP 47 locale code).
|
|
971
|
-
* @param {string} targetLocale - The locale code of the language to translate the content into (BCP 47 locale code).
|
|
972
|
-
* @param {string[]} [approvedLocale] - An optional array of approved target locales.
|
|
973
|
-
*
|
|
974
|
-
* @returns {boolean} - Returns `true` if translation is required, otherwise `false`.
|
|
975
|
-
*/
|
|
976
|
-
export declare function requiresTranslation(sourceLocale: string, targetLocale: string, approvedLocales?: string[], customMapping?: CustomMapping): boolean;
|
|
977
|
-
/**
|
|
978
|
-
* Determines the best matching locale from the provided approved locales list.
|
|
979
|
-
* @param {string | string[]} locales - A single locale or an array of locales sorted in preference order.
|
|
980
|
-
* @param {string[]} [approvedLocales=this.locales] - An array of approved locales, also sorted by preference.
|
|
981
|
-
* @returns {string | undefined} - The best matching locale from the approvedLocales list, or undefined if no match is found.
|
|
982
|
-
*/
|
|
983
|
-
export declare function determineLocale(locales: string | string[], approvedLocales?: string[] | undefined, customMapping?: CustomMapping | undefined): string | undefined;
|
|
984
|
-
/**
|
|
985
|
-
* Get the text direction for a given locale code using the Intl.Locale API.
|
|
986
|
-
*
|
|
987
|
-
* @param {string} locale - A BCP-47 locale code.
|
|
988
|
-
* @returns {string} 'rtl' if the locale is right-to-left; otherwise 'ltr'.
|
|
989
|
-
*/
|
|
990
|
-
export declare function getLocaleDirection(locale: string): 'ltr' | 'rtl';
|
|
991
|
-
/**
|
|
992
|
-
* Resolves the alias locale for a given locale.
|
|
993
|
-
* @param {string} locale - The locale to resolve the alias locale for
|
|
994
|
-
* @param {CustomMapping} [customMapping] - The custom mapping to use for resolving the alias locale
|
|
995
|
-
* @returns {string} The alias locale
|
|
996
|
-
*/
|
|
997
|
-
export declare function resolveAliasLocale(locale: string, customMapping?: CustomMapping): string;
|
|
998
|
-
/**
|
|
999
|
-
* Checks if multiple BCP 47 locale codes represent the same dialect.
|
|
1000
|
-
* @param {string[]} locales - The BCP 47 locale codes to compare.
|
|
1001
|
-
* @returns {boolean} True if all BCP 47 codes represent the same dialect, false otherwise.
|
|
1002
|
-
*/
|
|
1003
|
-
export declare function isSameDialect(...locales: (string | string[])[]): boolean;
|
|
1004
|
-
/**
|
|
1005
|
-
* Checks if multiple BCP 47 locale codes represent the same language.
|
|
1006
|
-
* @param {string[]} locales - The BCP 47 locale codes to compare.
|
|
1007
|
-
* @returns {boolean} True if all BCP 47 codes represent the same language, false otherwise.
|
|
1008
|
-
*/
|
|
1009
|
-
export declare function isSameLanguage(...locales: (string | string[])[]): boolean;
|
|
1010
|
-
/**
|
|
1011
|
-
* Checks if a locale is a superset of another locale.
|
|
1012
|
-
* A subLocale is a subset of superLocale if it is an extension of superLocale or are otherwise identical.
|
|
1013
|
-
*
|
|
1014
|
-
* @param {string} superLocale - The locale to check if it is a superset of the other locale.
|
|
1015
|
-
* @param {string} subLocale - The locale to check if it is a subset of the other locale.
|
|
1016
|
-
* @returns {boolean} True if the first locale is a superset of the second locale, false otherwise.
|
|
1017
|
-
*/
|
|
1018
|
-
export declare function isSupersetLocale(superLocale: string, subLocale: string): boolean;
|
|
1019
786
|
export declare const API_VERSION = "2026-03-06.v1";
|
package/dist/index.js
CHANGED
|
@@ -47,30 +47,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
47
47
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
51
|
-
var t = {};
|
|
52
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
53
|
-
t[p] = s[p];
|
|
54
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
55
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
56
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
57
|
-
t[p[i]] = s[p[i]];
|
|
58
|
-
}
|
|
59
|
-
return t;
|
|
60
|
-
};
|
|
61
50
|
// ----- IMPORTS ----- //
|
|
62
|
-
import _requiresTranslation from '
|
|
63
|
-
import _determineLocale from './locales/determineLocale';
|
|
64
|
-
import { _formatNum, _formatCurrency, _formatList, _formatRelativeTime, _formatRelativeTimeFromDate, _formatDateTime, _formatListToParts, } from './formatting/format';
|
|
65
|
-
import _isSameLanguage from './locales/isSameLanguage';
|
|
66
|
-
import _getLocaleProperties from './locales/getLocaleProperties';
|
|
67
|
-
import _getLocaleEmoji from './locales/getLocaleEmoji';
|
|
68
|
-
import { _isValidLocale, _standardizeLocale } from './locales/isValidLocale';
|
|
69
|
-
import { _getLocaleName } from './locales/getLocaleName';
|
|
70
|
-
import { _getLocaleDirection } from './locales/getLocaleDirection';
|
|
51
|
+
import { LocaleConfig, determineLocale as _determineLocale, getRegionProperties as _getRegionProperties, isValidLocale as _isValidLocale, requiresTranslation as _requiresTranslation, resolveAliasLocale as _resolveAliasLocale, resolveCanonicalLocale as _resolveCanonicalLocale, standardizeLocale as _standardizeLocale, } from '@generaltranslation/format';
|
|
71
52
|
import { libraryDefaultLocale } from './settings/settings';
|
|
72
|
-
import _isSameDialect from './locales/isSameDialect';
|
|
73
|
-
import _isSupersetLocale from './locales/isSupersetLocale';
|
|
74
53
|
import { noSourceLocaleProvidedError, noTargetLocaleProvidedError, invalidLocaleError, invalidLocalesError, noProjectIdProvidedError, noApiKeyProvidedError, } from './logging/errors';
|
|
75
54
|
import { gtInstanceLogger } from './logging/logger';
|
|
76
55
|
import _translateMany from './translate/translateMany';
|
|
@@ -79,9 +58,6 @@ import _enqueueFiles from './translate/enqueueFiles';
|
|
|
79
58
|
import _createTag from './translate/createTag';
|
|
80
59
|
import _downloadFileBatch from './translate/downloadFileBatch';
|
|
81
60
|
import _submitUserEditDiffs from './translate/submitUserEditDiffs';
|
|
82
|
-
import { _getRegionProperties, } from './locales/getRegionProperties';
|
|
83
|
-
import { _resolveAliasLocale } from './locales/resolveAliasLocale';
|
|
84
|
-
import { _resolveCanonicalLocale } from './locales/resolveCanonicalLocale';
|
|
85
61
|
import _uploadSourceFiles from './translate/uploadSourceFiles';
|
|
86
62
|
import _uploadTranslations from './translate/uploadTranslations';
|
|
87
63
|
import _querySourceFile from './translate/querySourceFile';
|
|
@@ -95,9 +71,8 @@ import _processFileMoves from './translate/processFileMoves';
|
|
|
95
71
|
import _getOrphanedFiles from './translate/getOrphanedFiles';
|
|
96
72
|
import _publishFiles from './translate/publishFiles';
|
|
97
73
|
import { API_VERSION as _API_VERSION } from './translate/api';
|
|
98
|
-
|
|
99
|
-
export {
|
|
100
|
-
export { formatCutoff, formatMessage, isValidLocale, resolveCanonicalLocale, standardizeLocale, } from './core';
|
|
74
|
+
export { LocaleConfig, } from '@generaltranslation/format';
|
|
75
|
+
export { determineLocale, formatCurrency, formatCutoff, formatDateTime, formatList, formatListToParts, formatMessage, formatNum, formatRelativeTime, formatRelativeTimeFromDate, getLocaleDirection, getLocaleEmoji, getLocaleName, getLocaleProperties, getRegionProperties, isSameDialect, isSameLanguage, isSupersetLocale, isValidLocale, requiresTranslation, resolveAliasLocale, resolveCanonicalLocale, standardizeLocale, } from '@generaltranslation/format';
|
|
101
76
|
/**
|
|
102
77
|
* GT is the core driver for the General Translation library.
|
|
103
78
|
* This class provides functionality for locale management, formatting, and translation operations.
|
|
@@ -1367,298 +1342,4 @@ var GT = /** @class */ (function () {
|
|
|
1367
1342
|
return GT;
|
|
1368
1343
|
}());
|
|
1369
1344
|
export { GT };
|
|
1370
|
-
// ============================================================ //
|
|
1371
|
-
// Utility methods //
|
|
1372
|
-
// ============================================================ //
|
|
1373
|
-
// -------------- Formatting -------------- //
|
|
1374
|
-
/**
|
|
1375
|
-
* Formats a number according to the specified locales and options.
|
|
1376
|
-
* @param {Object} params - The parameters for the number formatting.
|
|
1377
|
-
* @param {number} params.value - The number to format.
|
|
1378
|
-
* @param {Intl.NumberFormatOptions} [params.options] - Additional options for number formatting.
|
|
1379
|
-
* @param {string | string[]} [params.options.locales] - The locales to use for formatting.
|
|
1380
|
-
* @returns {string} The formatted number.
|
|
1381
|
-
*/
|
|
1382
|
-
export function formatNum(number, options) {
|
|
1383
|
-
return _formatNum({
|
|
1384
|
-
value: number,
|
|
1385
|
-
locales: options.locales,
|
|
1386
|
-
options: options,
|
|
1387
|
-
});
|
|
1388
|
-
}
|
|
1389
|
-
/**
|
|
1390
|
-
* Formats a date according to the specified languages and options.
|
|
1391
|
-
* @param {Object} params - The parameters for the date formatting.
|
|
1392
|
-
* @param {Date} params.value - The date to format.
|
|
1393
|
-
* @param {Intl.DateTimeFormatOptions} [params.options] - Additional options for date formatting.
|
|
1394
|
-
* @param {string | string[]} [params.options.locales] - The languages to use for formatting.
|
|
1395
|
-
* @returns {string} The formatted date.
|
|
1396
|
-
*/
|
|
1397
|
-
export function formatDateTime(date, options) {
|
|
1398
|
-
return _formatDateTime({
|
|
1399
|
-
value: date,
|
|
1400
|
-
locales: options === null || options === void 0 ? void 0 : options.locales,
|
|
1401
|
-
options: options,
|
|
1402
|
-
});
|
|
1403
|
-
}
|
|
1404
|
-
/**
|
|
1405
|
-
* Formats a currency value according to the specified languages, currency, and options.
|
|
1406
|
-
* @param {Object} params - The parameters for the currency formatting.
|
|
1407
|
-
* @param {number} params.value - The currency value to format.
|
|
1408
|
-
* @param {string} params.currency - The currency code (e.g., 'USD').
|
|
1409
|
-
* @param {Intl.NumberFormatOptions} [params.options={}] - Additional options for currency formatting.
|
|
1410
|
-
* @param {string | string[]} [params.options.locales] - The locale codes to use for formatting.
|
|
1411
|
-
* @returns {string} The formatted currency value.
|
|
1412
|
-
*/
|
|
1413
|
-
export function formatCurrency(value, currency, options) {
|
|
1414
|
-
return _formatCurrency({
|
|
1415
|
-
value: value,
|
|
1416
|
-
currency: currency,
|
|
1417
|
-
locales: options.locales,
|
|
1418
|
-
options: options,
|
|
1419
|
-
});
|
|
1420
|
-
}
|
|
1421
|
-
/**
|
|
1422
|
-
* Formats a list of items according to the specified locales and options.
|
|
1423
|
-
* @param {Object} params - The parameters for the list formatting.
|
|
1424
|
-
* @param {Array<string | number>} params.value - The list of items to format.
|
|
1425
|
-
* @param {Intl.ListFormatOptions} [params.options={}] - Additional options for list formatting.
|
|
1426
|
-
* @param {string | string[]} [params.options.locales] - The locales to use for formatting.
|
|
1427
|
-
* @returns {string} The formatted list.
|
|
1428
|
-
*/
|
|
1429
|
-
export function formatList(array, options) {
|
|
1430
|
-
return _formatList({
|
|
1431
|
-
value: array,
|
|
1432
|
-
locales: options.locales,
|
|
1433
|
-
options: options,
|
|
1434
|
-
});
|
|
1435
|
-
}
|
|
1436
|
-
/**
|
|
1437
|
-
* Formats a list of items according to the specified locales and options.
|
|
1438
|
-
* @param {Array<T>} array - The list of items to format.
|
|
1439
|
-
* @param {Object} [options] - Additional options for list formatting.
|
|
1440
|
-
* @param {string | string[]} [options.locales] - The locales to use for formatting.
|
|
1441
|
-
* @param {Intl.ListFormatOptions} [options] - Additional Intl.ListFormat options.
|
|
1442
|
-
* @returns {Array<T | string>} The formatted list parts.
|
|
1443
|
-
*/
|
|
1444
|
-
export function formatListToParts(array, options) {
|
|
1445
|
-
return _formatListToParts({
|
|
1446
|
-
value: array,
|
|
1447
|
-
locales: options === null || options === void 0 ? void 0 : options.locales,
|
|
1448
|
-
options: options,
|
|
1449
|
-
});
|
|
1450
|
-
}
|
|
1451
|
-
/**
|
|
1452
|
-
* Formats a relative time value according to the specified locales and options.
|
|
1453
|
-
* @param {Object} params - The parameters for the relative time formatting.
|
|
1454
|
-
* @param {number} params.value - The relative time value to format.
|
|
1455
|
-
* @param {Intl.RelativeTimeFormatUnit} params.unit - The unit of time (e.g., 'second', 'minute', 'hour', 'day', 'week', 'month', 'year').
|
|
1456
|
-
* @param {Intl.RelativeTimeFormatOptions} [params.options={}] - Additional options for relative time formatting.
|
|
1457
|
-
* @param {string | string[]} [params.options.locales] - The locales to use for formatting.
|
|
1458
|
-
* @returns {string} The formatted relative time string.
|
|
1459
|
-
*/
|
|
1460
|
-
export function formatRelativeTime(value, unit, options) {
|
|
1461
|
-
return _formatRelativeTime({
|
|
1462
|
-
value: value,
|
|
1463
|
-
unit: unit,
|
|
1464
|
-
locales: options.locales,
|
|
1465
|
-
options: options,
|
|
1466
|
-
});
|
|
1467
|
-
}
|
|
1468
|
-
/**
|
|
1469
|
-
* Formats a relative time string from a Date, automatically selecting the best unit.
|
|
1470
|
-
* @param {Date} date - The date to format relative to now.
|
|
1471
|
-
* @param {Object} options - Formatting options.
|
|
1472
|
-
* @param {string | string[]} options.locales - The locales to use for formatting.
|
|
1473
|
-
* @param {Intl.RelativeTimeFormatOptions} [options] - Additional Intl.RelativeTimeFormat options.
|
|
1474
|
-
* @returns {string} The formatted relative time string (e.g., "2 hours ago", "in 3 days").
|
|
1475
|
-
*/
|
|
1476
|
-
export function formatRelativeTimeFromDate(date, options) {
|
|
1477
|
-
var locales = options.locales, baseDate = options.baseDate, intlOptions = __rest(options, ["locales", "baseDate"]);
|
|
1478
|
-
return _formatRelativeTimeFromDate({
|
|
1479
|
-
date: date,
|
|
1480
|
-
baseDate: baseDate !== null && baseDate !== void 0 ? baseDate : new Date(),
|
|
1481
|
-
locales: locales,
|
|
1482
|
-
options: intlOptions,
|
|
1483
|
-
});
|
|
1484
|
-
}
|
|
1485
|
-
// -------------- Locale Properties -------------- //
|
|
1486
|
-
/**
|
|
1487
|
-
* Retrieves the display name of locale code using Intl.DisplayNames.
|
|
1488
|
-
*
|
|
1489
|
-
* @param {string} locale - A BCP-47 locale code.
|
|
1490
|
-
* @param {string} [defaultLocale] - The default locale to use for formatting.
|
|
1491
|
-
* @param {CustomMapping} [customMapping] - A custom mapping of locale codes to their names.
|
|
1492
|
-
* @returns {string} The display name corresponding to the code.
|
|
1493
|
-
*/
|
|
1494
|
-
export function getLocaleName(locale, defaultLocale, customMapping) {
|
|
1495
|
-
return _getLocaleName(locale, defaultLocale, customMapping);
|
|
1496
|
-
}
|
|
1497
|
-
/**
|
|
1498
|
-
* Retrieves an emoji based on a given locale code, taking into account region, language, and specific exceptions.
|
|
1499
|
-
*
|
|
1500
|
-
* This function uses the locale's region (if present) to select an emoji or falls back on default emojis for certain languages.
|
|
1501
|
-
*
|
|
1502
|
-
* @param locale - A string representing the locale code (e.g., 'en-US', 'fr-CA').
|
|
1503
|
-
* @param {CustomMapping} [customMapping] - A custom mapping of locale codes to their names.
|
|
1504
|
-
* @returns The emoji representing the locale or its region, or a default emoji if no specific match is found.
|
|
1505
|
-
*/
|
|
1506
|
-
export function getLocaleEmoji(locale, customMapping) {
|
|
1507
|
-
return _getLocaleEmoji(locale, customMapping);
|
|
1508
|
-
}
|
|
1509
|
-
/**
|
|
1510
|
-
* Generates linguistic details for a given locale code.
|
|
1511
|
-
*
|
|
1512
|
-
* This function returns information about the locale,
|
|
1513
|
-
* script, and region of a given language code both in a standard form and in a maximized form (with likely script and region).
|
|
1514
|
-
* The function provides these names in both your default language and native forms, and an associated emoji.
|
|
1515
|
-
*
|
|
1516
|
-
* @param {string} locale - The locale code to get properties for (e.g., "de-AT").
|
|
1517
|
-
* @param {string} [defaultLocale] - The default locale to use for formatting.
|
|
1518
|
-
* @param {CustomMapping} [customMapping] - A custom mapping of locale codes to their names.
|
|
1519
|
-
* @returns {LocaleProperties} - An object containing detailed information about the locale.
|
|
1520
|
-
*
|
|
1521
|
-
* @property {string} code - The full locale code, e.g., "de-AT".
|
|
1522
|
-
* @property {string} name - Language name in the default display language, e.g., "Austrian German".
|
|
1523
|
-
* @property {string} nativeName - Language name in the locale's native language, e.g., "Österreichisches Deutsch".
|
|
1524
|
-
* @property {string} languageCode - The base language code, e.g., "de".
|
|
1525
|
-
* @property {string} languageName - The language name in the default display language, e.g., "German".
|
|
1526
|
-
* @property {string} nativeLanguageName - The language name in the native language, e.g., "Deutsch".
|
|
1527
|
-
* @property {string} nameWithRegionCode - Language name with region in the default language, e.g., "German (AT)".
|
|
1528
|
-
* @property {string} nativeNameWithRegionCode - Language name with region in the native language, e.g., "Deutsch (AT)".
|
|
1529
|
-
* @property {string} regionCode - The region code from maximization, e.g., "AT".
|
|
1530
|
-
* @property {string} regionName - The region name in the default display language, e.g., "Austria".
|
|
1531
|
-
* @property {string} nativeRegionName - The region name in the native language, e.g., "Österreich".
|
|
1532
|
-
* @property {string} scriptCode - The script code from maximization, e.g., "Latn".
|
|
1533
|
-
* @property {string} scriptName - The script name in the default display language, e.g., "Latin".
|
|
1534
|
-
* @property {string} nativeScriptName - The script name in the native language, e.g., "Lateinisch".
|
|
1535
|
-
* @property {string} maximizedCode - The maximized locale code, e.g., "de-Latn-AT".
|
|
1536
|
-
* @property {string} maximizedName - Maximized locale name with likely script in the default language, e.g., "Austrian German (Latin)".
|
|
1537
|
-
* @property {string} nativeMaximizedName - Maximized locale name in the native language, e.g., "Österreichisches Deutsch (Lateinisch)".
|
|
1538
|
-
* @property {string} minimizedCode - Minimized locale code, e.g., "de-AT" (or "de" for "de-DE").
|
|
1539
|
-
* @property {string} minimizedName - Minimized language name in the default language, e.g., "Austrian German".
|
|
1540
|
-
* @property {string} nativeMinimizedName - Minimized language name in the native language, e.g., "Österreichisches Deutsch".
|
|
1541
|
-
* @property {string} emoji - The emoji associated with the locale's region, if applicable.
|
|
1542
|
-
*/
|
|
1543
|
-
export function getLocaleProperties(locale, defaultLocale, customMapping) {
|
|
1544
|
-
return _getLocaleProperties(locale, defaultLocale, customMapping);
|
|
1545
|
-
}
|
|
1546
|
-
/**
|
|
1547
|
-
* Retrieves multiple properties for a given region code, including:
|
|
1548
|
-
* - `code`: the original region code
|
|
1549
|
-
* - `name`: the localized display name
|
|
1550
|
-
* - `emoji`: the associated flag or symbol
|
|
1551
|
-
*
|
|
1552
|
-
* Behavior:
|
|
1553
|
-
* - Accepts ISO 3166-1 alpha-2 or UN M.49 region codes (e.g., `"US"`, `"FR"`, `"419"`).
|
|
1554
|
-
* - If `customMapping` contains a `name` or `emoji` for the region, those override the default values.
|
|
1555
|
-
* - Otherwise, uses `Intl.DisplayNames` to get the localized region name in the given `defaultLocale`,
|
|
1556
|
-
* falling back to `libraryDefaultLocale`.
|
|
1557
|
-
* - Falls back to the region code as `name` if display name resolution fails.
|
|
1558
|
-
* - Falls back to `defaultEmoji` if no emoji mapping is found in `emojis` or `customMapping`.
|
|
1559
|
-
*
|
|
1560
|
-
* @param {string} region - The region code to look up (e.g., `"US"`, `"GB"`, `"DE"`).
|
|
1561
|
-
* @param {string} [defaultLocale=libraryDefaultLocale] - The locale to use when localizing the region name.
|
|
1562
|
-
* @param {CustomRegionMapping} [customMapping] - Optional mapping of region codes to custom names and/or emojis.
|
|
1563
|
-
* @returns {{ code: string, name: string, emoji: string }} An object containing:
|
|
1564
|
-
* - `code`: the input region code
|
|
1565
|
-
* - `name`: the localized or custom region name
|
|
1566
|
-
* - `emoji`: the matching emoji flag or symbol
|
|
1567
|
-
*
|
|
1568
|
-
* @example
|
|
1569
|
-
* getRegionProperties('US', 'en');
|
|
1570
|
-
* // => { code: 'US', name: 'United States', emoji: '🇺🇸' }
|
|
1571
|
-
*
|
|
1572
|
-
* @example
|
|
1573
|
-
* getRegionProperties('US', 'fr');
|
|
1574
|
-
* // => { code: 'US', name: 'États-Unis', emoji: '🇺🇸' }
|
|
1575
|
-
*
|
|
1576
|
-
* @example
|
|
1577
|
-
* getRegionProperties('US', 'en', { US: { name: 'USA', emoji: '🗽' } });
|
|
1578
|
-
* // => { code: 'US', name: 'USA', emoji: '🗽' }
|
|
1579
|
-
*/
|
|
1580
|
-
export function getRegionProperties(region, defaultLocale, customMapping) {
|
|
1581
|
-
return _getRegionProperties(region, defaultLocale, customMapping);
|
|
1582
|
-
}
|
|
1583
|
-
/**
|
|
1584
|
-
* Determines whether a translation is required based on the source and target locales.
|
|
1585
|
-
*
|
|
1586
|
-
* - If the target locale is not specified, the function returns `false`, as translation is not needed.
|
|
1587
|
-
* - If the source and target locale are the same, returns `false`, indicating that no translation is necessary.
|
|
1588
|
-
* - If the `approvedLocales` array is provided, and the target locale is not within that array, the function also returns `false`.
|
|
1589
|
-
* - Otherwise, it returns `true`, meaning that a translation is required.
|
|
1590
|
-
*
|
|
1591
|
-
* @param {string} sourceLocale - The locale code for the original content (BCP 47 locale code).
|
|
1592
|
-
* @param {string} targetLocale - The locale code of the language to translate the content into (BCP 47 locale code).
|
|
1593
|
-
* @param {string[]} [approvedLocale] - An optional array of approved target locales.
|
|
1594
|
-
*
|
|
1595
|
-
* @returns {boolean} - Returns `true` if translation is required, otherwise `false`.
|
|
1596
|
-
*/
|
|
1597
|
-
export function requiresTranslation(sourceLocale, targetLocale, approvedLocales, customMapping) {
|
|
1598
|
-
return _requiresTranslation(sourceLocale, targetLocale, approvedLocales, customMapping);
|
|
1599
|
-
}
|
|
1600
|
-
/**
|
|
1601
|
-
* Determines the best matching locale from the provided approved locales list.
|
|
1602
|
-
* @param {string | string[]} locales - A single locale or an array of locales sorted in preference order.
|
|
1603
|
-
* @param {string[]} [approvedLocales=this.locales] - An array of approved locales, also sorted by preference.
|
|
1604
|
-
* @returns {string | undefined} - The best matching locale from the approvedLocales list, or undefined if no match is found.
|
|
1605
|
-
*/
|
|
1606
|
-
export function determineLocale(locales, approvedLocales, customMapping) {
|
|
1607
|
-
if (approvedLocales === void 0) { approvedLocales = []; }
|
|
1608
|
-
if (customMapping === void 0) { customMapping = undefined; }
|
|
1609
|
-
return _determineLocale(locales, approvedLocales, customMapping);
|
|
1610
|
-
}
|
|
1611
|
-
/**
|
|
1612
|
-
* Get the text direction for a given locale code using the Intl.Locale API.
|
|
1613
|
-
*
|
|
1614
|
-
* @param {string} locale - A BCP-47 locale code.
|
|
1615
|
-
* @returns {string} 'rtl' if the locale is right-to-left; otherwise 'ltr'.
|
|
1616
|
-
*/
|
|
1617
|
-
export function getLocaleDirection(locale) {
|
|
1618
|
-
return _getLocaleDirection(locale);
|
|
1619
|
-
}
|
|
1620
|
-
/**
|
|
1621
|
-
* Resolves the alias locale for a given locale.
|
|
1622
|
-
* @param {string} locale - The locale to resolve the alias locale for
|
|
1623
|
-
* @param {CustomMapping} [customMapping] - The custom mapping to use for resolving the alias locale
|
|
1624
|
-
* @returns {string} The alias locale
|
|
1625
|
-
*/
|
|
1626
|
-
export function resolveAliasLocale(locale, customMapping) {
|
|
1627
|
-
return _resolveAliasLocale(locale, customMapping);
|
|
1628
|
-
}
|
|
1629
|
-
/**
|
|
1630
|
-
* Checks if multiple BCP 47 locale codes represent the same dialect.
|
|
1631
|
-
* @param {string[]} locales - The BCP 47 locale codes to compare.
|
|
1632
|
-
* @returns {boolean} True if all BCP 47 codes represent the same dialect, false otherwise.
|
|
1633
|
-
*/
|
|
1634
|
-
export function isSameDialect() {
|
|
1635
|
-
var locales = [];
|
|
1636
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1637
|
-
locales[_i] = arguments[_i];
|
|
1638
|
-
}
|
|
1639
|
-
return _isSameDialect.apply(void 0, locales);
|
|
1640
|
-
}
|
|
1641
|
-
/**
|
|
1642
|
-
* Checks if multiple BCP 47 locale codes represent the same language.
|
|
1643
|
-
* @param {string[]} locales - The BCP 47 locale codes to compare.
|
|
1644
|
-
* @returns {boolean} True if all BCP 47 codes represent the same language, false otherwise.
|
|
1645
|
-
*/
|
|
1646
|
-
export function isSameLanguage() {
|
|
1647
|
-
var locales = [];
|
|
1648
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1649
|
-
locales[_i] = arguments[_i];
|
|
1650
|
-
}
|
|
1651
|
-
return _isSameLanguage.apply(void 0, locales);
|
|
1652
|
-
}
|
|
1653
|
-
/**
|
|
1654
|
-
* Checks if a locale is a superset of another locale.
|
|
1655
|
-
* A subLocale is a subset of superLocale if it is an extension of superLocale or are otherwise identical.
|
|
1656
|
-
*
|
|
1657
|
-
* @param {string} superLocale - The locale to check if it is a superset of the other locale.
|
|
1658
|
-
* @param {string} subLocale - The locale to check if it is a subset of the other locale.
|
|
1659
|
-
* @returns {boolean} True if the first locale is a superset of the second locale, false otherwise.
|
|
1660
|
-
*/
|
|
1661
|
-
export function isSupersetLocale(superLocale, subLocale) {
|
|
1662
|
-
return _isSupersetLocale(superLocale, subLocale);
|
|
1663
|
-
}
|
|
1664
1345
|
export var API_VERSION = _API_VERSION;
|