Skip to content

Commit 9461824

Browse files
committed
refactor: added JSDoc comments to exported functions in locales.ts
1 parent 401a172 commit 9461824

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed

packages/cli/src/cli/cmd/cleanup.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ export default new Command()
1111
.command("cleanup")
1212
.description("Remove keys from target files that do not exist in the source file")
1313
.helpOption("-h, --help", "Show help")
14-
.option("--locale <locale>", "Clean up only the specified target locale.If not provided, processes all target locales.")
15-
.option("--bucket <bucket>", " Clean up only the specified bucket type.If not provided, processes all buckets.")
16-
.option("--dry-run", "Show what would be removed without actually modifying any files.")
14+
.option("--locale <locale>", "Clean up only the specified target locale")
15+
.option("--bucket <bucket>", " Clean up only the specified bucket type")
16+
.option("--dry-run", "Show what would be removed without actually modifying any files")
1717
.option("--verbose", "Show detailed output including:\n" +
1818
" - List of keys that would be removed.\n" +
1919
" - Processing steps.")

packages/cli/src/cli/cmd/i18n.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ export default new Command()
2525
.option("--locale <locale>", "Locale to process", (val: string, prev: string[]) => (prev ? [...prev, val] : [val]))
2626
.option("--bucket <bucket>", "Bucket to process", (val: string, prev: string[]) => (prev ? [...prev, val] : [val]))
2727
.option("--key <key>", "Key to process.Process only a specific translation key. Useful for debugging or updating a single entry.")
28-
.option("--frozen", `Run in read-only mode - fails if any translations need updating.Useful for CI/CD pipelines to detect missing translations.`)
28+
.option("--frozen", `Run in read-only mode - fails if any translations need updating. Useful for CI/CD pipelines to detect missing translations.`)
2929
.option("--force", "Ignore lockfile and process all keys, forcing a full re-translation.Use with caution as this may incur higher API costs.")
3030
.option("--verbose", "Show detailed output including intermediate processing data and API communication details.")
3131
.option("--interactive", "Enable interactive mode for reviewing and editing translations before they are applied.")
32-
.option("--api-key <api-key>", "Explicitly set the API key to use.Override the default API key from settings.")
33-
.option("--debug", "Pause execution at start for debugging purposes.Waits for user confirmation before proceeding.")
32+
.option("--api-key <api-key>", "Explicitly set the API key to use. Override the default API key from settings.")
33+
.option("--debug", "Pause execution at start for debugging purposes. Waits for user confirmation before proceeding.")
3434
.option("--strict", "Stop processing on first error instead of continuing with other locales/buckets.")
3535
.action(async function (options) {
3636
updateGitignore();

packages/spec/src/locales.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,19 @@ export const localeCodeSchema = Z.string().refine((value) => localeCodes.include
221221
message: "Invalid locale code",
222222
});
223223

224+
/**
225+
* Resolves a locale code to its full locale representation.
226+
*
227+
* If the provided locale code is already a full locale code, it returns as is.
228+
* If the provided locale code is a short locale code, it returns the first corresponding full locale.
229+
* If the locale code is not found, it throws an error.
230+
*
231+
* @param {localeCodes} value - The locale code to resolve (either short or full)
232+
* @return {LocaleCodeFull} The resolved full locale code
233+
* @throws {Error} If the provided locale code is invalid.
234+
*/
235+
236+
224237
export const resolveLocaleCode = (value: LocaleCode): LocaleCodeFull => {
225238
const existingFullLocaleCode = Object.values(localeMap)
226239
.flat()
@@ -239,6 +252,15 @@ export const resolveLocaleCode = (value: LocaleCode): LocaleCodeFull => {
239252
throw new Error(`Invalid locale code: ${value}`);
240253
};
241254

255+
256+
/**
257+
* Determines the delimiter used in a locale code
258+
*
259+
* @param {string} locale - the locale string (e.g.,"en_US","en-GB")
260+
* @return { string | null} - The delimiter ("_" or "-") if found, otherwise `null`.
261+
*/
262+
263+
242264
export const getLocaleCodeDelimiter = (locale: string): string | null => {
243265
if (locale.includes("_")) {
244266
return "_";
@@ -249,6 +271,16 @@ export const getLocaleCodeDelimiter = (locale: string): string | null => {
249271
}
250272
};
251273

274+
/**
275+
* Replaces the delimiter in a locale string with the specified delimiter.
276+
*
277+
* @param {string}locale - The locale string (e.g.,"en_US", "en-GB").
278+
* @param {"-" | "_" | null} [delimiter] - The new delimiter to replace the existing one.
279+
* @returns {string} The locale string with the replaced delimiter, or the original locale if no delimiter is provided.
280+
*/
281+
282+
283+
252284
export const resolveOverridenLocale = (locale: string, delimiter?: "-" | "_" | null): string => {
253285
if (!delimiter) {
254286
return locale;
@@ -262,6 +294,15 @@ export const resolveOverridenLocale = (locale: string, delimiter?: "-" | "_" | n
262294
return locale.replace(currentDelimiter, delimiter);
263295
};
264296

265-
export function normalizeLocale(locale: string) {
297+
/**
298+
* Normalizes a locale string by replacing underscores with hyphens
299+
* and removing the "r" in certain regional codes (e.g., "fr-rCA" → "fr-CA")
300+
*
301+
* @param {string} locale - The locale string (e.g.,"en_US", "en-GB").
302+
* @return {string} The normalized locale string.
303+
*/
304+
305+
306+
export const normalizeLocale = (locale: string): string => {
266307
return locale.replaceAll("_", "-").replace(/([a-z]{2,3}-)r/, "$1");
267308
}

0 commit comments

Comments
 (0)