gt-i18n 0.0.0 → 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ declare const _default: {
2
+ warn(message: string): void;
3
+ error(message: string): void;
4
+ info(message: string): void;
5
+ debug(message: string): void;
6
+ };
7
+ export default _default;
@@ -0,0 +1 @@
1
+ export declare const interpolationFailureWarning = "gt-i18n warning: String interpolation failed.";
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Extracts the original interpolated message string.
3
+ * If the message cannot be decoded (i.e., it does not contain a colon separator),
4
+ * the input is returned as-is.
5
+ * @param encodedMsg The message to decode.
6
+ * @returns The decoded message, or the input if it cannot be decoded.
7
+ */
8
+ export declare function decodeMsg(encodedMsg: string): string;
9
+ export declare function decodeMsg<T extends null | undefined>(encodedMsg: T): T;
10
+ export declare function decodeMsg<T extends string | null | undefined>(encodedMsg: T): T extends string ? string : T;
@@ -0,0 +1,7 @@
1
+ import { InlineTranslationOptions } from '../types';
2
+ /**
3
+ * Decodes the options from an encoded message.
4
+ * @param encodedMsg The message to decode.
5
+ * @returns The decoded options.
6
+ */
7
+ export declare function decodeOptions(encodedMsg: string): InlineTranslationOptions | null;
@@ -0,0 +1,3 @@
1
+ export * from './msg';
2
+ export * from './decodeMsg';
3
+ export * from './decodeOptions';
@@ -0,0 +1,29 @@
1
+ import { InlineTranslationOptions } from '../types';
2
+ /**
3
+ * Registers a message to be translated. Returns the message unchanged if no options are provided.
4
+ * @param message The message to encode.
5
+ * @param options The options to encode.
6
+ * @returns The encoded message.
7
+ *
8
+ * @note - This function registers the message before the build process. The actual translation does not
9
+ * occur until the m() function is invoked.
10
+ *
11
+ * @note - Message format
12
+ * A message is broken into two parts separated by colons:
13
+ * - interpolated content - the content with interpolated variables
14
+ * - hash + options - a unique identifier for the source content and options for the translation
15
+ *
16
+ * @example - Basic usage
17
+ *
18
+ * ```jsx
19
+ * import { msg } from 'gt-i18n';
20
+ * const message1 = msg('Hello, World!');
21
+ * console.log(message1); // "Hello, World!"
22
+ * const message2 = msg('Hello, {name}!', { name: 'Brian' });
23
+ * console.log(message2); // "Hello, Brian:eyIkX2hhc2giOiAiMHgxMjMiLCAiJF9zb3VyY2UiOiAiSGVsbG8sIHtuYW1lfSEiLCAibmFtZSI6ICJCcmlhbiJ9"
24
+ * ```
25
+ * eyIkX2hhc2giOiAiMHgxMjMiLCAiJF9zb3VyY2UiOiAiSGVsbG8sIHtuYW1lfSEiLCAibmFtZSI6ICJCcmlhbiJ9
26
+ * encodes to {"$_hash": "0x123", "$_source": "Hello, {name}!", "name": "Brian"}
27
+ */
28
+ export declare function msg<T extends string>(message: T): T;
29
+ export declare function msg<T extends string>(message: T, options: InlineTranslationOptions): string;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Checks if a message contains variables.
3
+ * @param message - The message to check.
4
+ * @returns True if the message contains variables, false otherwise.
5
+ *
6
+ * @example
7
+ * ```jsx
8
+ * import { icuMessageContainsVariables } from 'gt-i18n/messages/utils';
9
+ * const message = 'Hello {name}';
10
+ * console.log(icuMessageContainsVariables(message)); // true
11
+ * ```
12
+ */
13
+ export declare function icuMessageContainsVariables(message: string): boolean;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=types.cjs.min.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.cjs.min.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,17 @@
1
+ type BaseTranslationOptions = Record<string, any>;
2
+ type DictionaryTranslationOptions = BaseTranslationOptions;
3
+ type InlineTranslationOptions = BaseTranslationOptions & {
4
+ $context?: string;
5
+ $id?: string;
6
+ $_hash?: string;
7
+ /** @deprecated use {@link EncodedTranslationOptions} instead */
8
+ $_source?: string;
9
+ };
10
+ type InlineResolveOptions = BaseTranslationOptions;
11
+ type RuntimeTranslationOptions = {
12
+ locale?: string;
13
+ } & Omit<InlineTranslationOptions, 'id'>;
14
+ type MFunctionType = <T extends string | null | undefined>(encodedMsg: T, options?: Record<string, any>) => T extends string ? string : T;
15
+ type GTFunctionType = (message: string, options?: InlineTranslationOptions) => string;
16
+
17
+ export type { BaseTranslationOptions, DictionaryTranslationOptions, GTFunctionType, InlineResolveOptions, InlineTranslationOptions, MFunctionType, RuntimeTranslationOptions };
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=types.esm.min.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.esm.min.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import { BaseTranslationOptions } from '../types';
2
+ /**
3
+ * Given an object of options, returns an object with no gt-related options
4
+ *
5
+ * TODO: next major version, this should extract any sugar syntax options
6
+ * TODO: next major version, options should be Record<string, string>
7
+ */
8
+ export declare function extractVariables<T extends BaseTranslationOptions>(options: T): BaseTranslationOptions;
package/package.json CHANGED
@@ -1,12 +1,102 @@
1
1
  {
2
2
  "name": "gt-i18n",
3
- "version": "0.0.0",
4
- "description": "",
5
- "license": "UNLICENSED",
6
- "author": "",
7
- "type": "commonjs",
8
- "main": "index.js",
3
+ "version": "0.1.0",
4
+ "description": "Pure JS i18n library for General Translation",
5
+ "main": "dist/index.cjs.min.cjs",
6
+ "module": "dist/index.esm.min.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "CHANGELOG.md"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/generaltranslation/gt.git"
15
+ },
16
+ "keywords": [
17
+ "language",
18
+ "translation",
19
+ "internationalization",
20
+ "localization",
21
+ "translate",
22
+ "locale",
23
+ "i18n",
24
+ "toolkit",
25
+ "core"
26
+ ],
27
+ "author": "General Translation, Inc.",
28
+ "license": "FSL-1.1-ALv2",
29
+ "bugs": {
30
+ "url": "https://github.com/generaltranslation/gt/issues"
31
+ },
32
+ "homepage": "https://generaltranslation.com/",
33
+ "devDependencies": {
34
+ "@rollup/plugin-commonjs": "^28.0.1",
35
+ "@rollup/plugin-node-resolve": "^16.0.1",
36
+ "@rollup/plugin-terser": "^0.4.4",
37
+ "@rollup/plugin-typescript": "^12.1.1",
38
+ "@types/node": "^20.14.9",
39
+ "rollup": "^4.24.0",
40
+ "rollup-plugin-dts": "^6.1.1",
41
+ "tslib": "^2.8.0",
42
+ "typescript": "^5.6.2"
43
+ },
44
+ "typescript": {
45
+ "definition": "dist/index.d.ts"
46
+ },
47
+ "dependencies": {
48
+ "generaltranslation": "8.0.4",
49
+ "@generaltranslation/supported-locales": "2.0.27"
50
+ },
51
+ "exports": {
52
+ ".": {
53
+ "types": "./dist/index.d.ts",
54
+ "require": "./dist/index.cjs.min.cjs",
55
+ "import": "./dist/index.esm.min.mjs"
56
+ },
57
+ "./types": {
58
+ "types": "./dist/types.d.ts",
59
+ "require": "./dist/types.cjs.min.cjs",
60
+ "import": "./dist/types.esm.min.mjs"
61
+ },
62
+ "./fallbacks": {
63
+ "types": "./dist/fallbacks.d.ts",
64
+ "require": "./dist/fallbacks.cjs.min.cjs",
65
+ "import": "./dist/fallbacks.esm.min.mjs"
66
+ }
67
+ },
68
+ "typesVersions": {
69
+ "*": {
70
+ "types": [
71
+ "./dist/types.d.ts"
72
+ ],
73
+ "fallbacks": [
74
+ "./dist/fallbacks.d.ts"
75
+ ]
76
+ }
77
+ },
78
+ "compilerOptions": {
79
+ "baseUrl": ".",
80
+ "paths": {
81
+ "gt-i18n/types": [
82
+ "/dist/types"
83
+ ],
84
+ "gt-i18n/fallbacks": [
85
+ "/dist/fallbacks"
86
+ ]
87
+ }
88
+ },
9
89
  "scripts": {
10
- "test": "echo \"Error: no test specified\" && exit 1"
90
+ "build:release": "pnpm run build:clean",
91
+ "build:clean": "sh ../../scripts/clean.sh && pnpm run build",
92
+ "build": "rollup -c",
93
+ "lint": "eslint \"src/**/*.{js,ts}\"",
94
+ "lint:fix": "eslint \"src/**/*.{js,ts}\" --fix",
95
+ "test": "vitest run --config=./vitest.config.ts",
96
+ "test:watch": "vitest --config=./vitest.config.ts",
97
+ "release": "pnpm run build:clean && pnpm publish",
98
+ "release:alpha": "pnpm run build:clean && pnpm publish --tag alpha",
99
+ "release:beta": "pnpm run build:clean && pnpm publish --tag beta",
100
+ "release:latest": "pnpm run build:clean && pnpm publish --tag latest"
11
101
  }
12
- }
102
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # gt-i18n
2
-
3
- Placeholder while we work on this! :)