Skip to content

Commit

Permalink
Merge pull request #13 from matrix-org/t3chguy/localazy-custom-transl…
Browse files Browse the repository at this point in the history
…ations
  • Loading branch information
t3chguy authored Oct 2, 2023
2 parents 179328d + 334b107 commit 2fcae23
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ lib-cov
out
/dist
/lib
/src/*.js
/scripts/*.js
4 changes: 2 additions & 2 deletions scripts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ limitations under the License.

import fs from "fs";
import { isBinaryExpression, isStringLiteral, isTemplateLiteral, Node } from "@babel/types";
import { Translation, Translations } from "../src";
import { KEY_SEPARATOR, Translation, Translations } from "../src";

export const NESTING_KEY = process.env["NESTING_KEY"] || "|";
export const NESTING_KEY = process.env["NESTING_KEY"] || KEY_SEPARATOR;
export const INPUT_FILE = process.env["INPUT_FILE"] || 'src/i18n/strings/en_EN.json';
export const OUTPUT_FILE = process.env["OUTPUT_FILE"] || 'src/i18n/strings/en_EN.json';

Expand Down
3 changes: 3 additions & 0 deletions scripts/rekey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ const translation = _.get(sourceTranslations, oldPath);
if (!translation) {
throw new Error(`"${argv._[0]}" key not present in source translations`);
}
if (_.get(sourceTranslations, newPath)) {
throw new Error(`"${argv._[1]}" key already present in source translations`);
}

function updateTranslations(translations: Translations): void {
const value = _.get(translations, oldPath);
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

export const KEY_SEPARATOR = "|";

export * from "./utils";
export * from "./types";
4 changes: 3 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { KEY_SEPARATOR } from "./index";

/**
* Utility type for string dot notation for accessing nested object properties.
* Based on https://stackoverflow.com/a/58436959
Expand Down Expand Up @@ -57,7 +59,7 @@ type Join<K, P, S extends string = "."> = K extends string | number
* @typeParam MaxDepth the maximum depth to recurse to
* @returns a union type representing all dot (Separator) string notation keys which can access a Leaf (of LeafType)
*/
export type TranslationKey<T extends Translations> = Leaves<T, "|", string | { other: string }>;
export type TranslationKey<T extends Translations> = Leaves<T, typeof KEY_SEPARATOR, string | { other: string }, 4>;

export type Translation = string | {
one?: string;
Expand Down

0 comments on commit 2fcae23

Please sign in to comment.