WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"new": "changeset",
"new:empty": "changeset --empty",
"format": "prettier . --write",
"format:check": "prettier . --check"
"format:check": "prettier . --check",
},
"devDependencies": {
"@babel/generator": "^7.27.1",
Expand All @@ -31,4 +31,4 @@
"node-machine-id": "^1.1.12"
},
"packageManager": "[email protected]"
}
}
18 changes: 16 additions & 2 deletions packages/locales/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,19 @@
* - Script codes preserve their original case
* - Region codes are converted to uppercase
*/
export const LOCALE_REGEX =
/^([a-z]{2,3})(?:[-_]([A-Za-z]{4}))?(?:[-_]([A-Z]{2}|[0-9]{3}))?$/;
// export const LOCALE_REGEX =
// /^([a-z]{2,3})(?:[-_]([A-Za-z]{4}))?(?:[-_]([A-Z]{2}|[0-9]{3}))?$/;

/* The `export const LOCALE_REGEX` statement is defining a regular expression object named
`LOCALE_REGEX` that is used for parsing locale strings. The regular expression is constructed using
the `RegExp` constructor with the following components: */
export const LOCALE_REGEX = new RegExp(
[
'^',
'([a-z]{2,3})', // Language code
'(?:[-_]([A-Za-z]{4}))?', // Optional script code
'(?:[-_]([A-Z]{2}|[0-9]{3}))?', // Optional region code
'$'
].join(''),
'u' // Unicode flag for better Unicode support
);
31 changes: 25 additions & 6 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,35 @@ export class LingoDotDevEngine {
signal,
});

// if (!res.ok) {
// if (res.status >= 500 && res.status < 600) {
// const errorText = await res.text();
// throw new Error(
// `Server error (${res.status}): ${res.statusText}. ${errorText}. This may be due to temporary service issues.`,
// );
// } else if (res.status === 400) {
// throw new Error(`Invalid request: ${res.statusText}`);
// } else {
// const errorText = await res.text();
// throw new Error(errorText);
// }
// }

/* The above TypeScript code is handling errors from a fetch request. It checks if the response
`res` is not ok (i.e., the status is not in the 200-299 range). If the status code is in the
500-599 range, it throws an error indicating a server error along with the status code, status
text, and the error text received from the response. If the status code is 400, it throws an
error indicating an invalid request with the status text. For any other status codes, it throws
an error with the error text received from the response. */
Comment on lines +150 to +155
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This multi-line comment is unnecessarily verbose and simply restates what the code does. The code itself is self-explanatory with its clear condition checks and error messages. If documentation is needed, it should explain why this error handling strategy was chosen, not describe what each if-statement does.

Suggested change
/* The above TypeScript code is handling errors from a fetch request. It checks if the response
`res` is not ok (i.e., the status is not in the 200-299 range). If the status code is in the
500-599 range, it throws an error indicating a server error along with the status code, status
text, and the error text received from the response. If the status code is 400, it throws an
error indicating an invalid request with the status text. For any other status codes, it throws
an error with the error text received from the response. */

Copilot uses AI. Check for mistakes.
if (!res.ok) {
const errorText = await res.text(); // Retrieve error text once
if (res.status >= 500 && res.status < 600) {
const errorText = await res.text();
throw new Error(
`Server error (${res.status}): ${res.statusText}. ${errorText}. This may be due to temporary service issues.`,
);
} else if (res.status === 400) {
throw new Error(`Invalid request: ${res.statusText}`);
} else {
const errorText = await res.text();
throw new Error(errorText);
}
}
Expand Down Expand Up @@ -592,8 +611,8 @@ export class ReplexicaEngine extends LingoDotDevEngine {
if (!ReplexicaEngine.hasWarnedDeprecation) {
console.warn(
"ReplexicaEngine is deprecated and will be removed in a future release. " +
"Please use LingoDotDevEngine instead. " +
"See https://lingo.dev/cli for more information.",
"Please use LingoDotDevEngine instead. " +
"See https://lingo.dev/cli for more information.",
);
ReplexicaEngine.hasWarnedDeprecation = true;
}
Expand All @@ -611,8 +630,8 @@ export class LingoEngine extends LingoDotDevEngine {
if (!LingoEngine.hasWarnedDeprecation) {
console.warn(
"LingoEngine is deprecated and will be removed in a future release. " +
"Please use LingoDotDevEngine instead. " +
"See https://lingo.dev/cli for more information.",
"Please use LingoDotDevEngine instead. " +
"See https://lingo.dev/cli for more information.",
);
LingoEngine.hasWarnedDeprecation = true;
}
Expand Down
11 changes: 10 additions & 1 deletion scripts/docs/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ import { Octokit } from "@octokit/rest";
import * as prettier from "prettier";

export function getRepoRoot(): string {
const __filename = fileURLToPath(import.meta.url);
const metadataUrl = import.meta.url;
/* This code snippet is checking if the `metadataUrl` variable is falsy (in this case, `undefined`).
If `metadataUrl` is `undefined`, it means that the `import.meta.url` feature is not supported or
not available in the current environment. In that case, the code throws an error with the message
"import.meta.url is undefined" to indicate that the script relies on `import.meta.url` and cannot
proceed without it. */
if (!metadataUrl) {
throw new Error("import.meta.url is undefined");
}
const __filename = fileURLToPath(metadataUrl);
const __dirname = path.dirname(__filename);
let currentDir = __dirname;

Expand Down
Loading