Skip to content

Commit

Permalink
remove keySearch/keyReplace feature
Browse files Browse the repository at this point in the history
  • Loading branch information
fkirc committed Jul 25, 2023
1 parent 3fc4d46 commit a95e9d2
Show file tree
Hide file tree
Showing 10 changed files with 6 additions and 31 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# 2.0.0

- Remove overwriteOutdated feature
- Remove translation cache feature
- Improve behaviour of keySearch/keyReplace
- Remove keySearch/keyReplace feature
- Expand YAML sample script

# 1.9.2

Expand Down
2 changes: 1 addition & 1 deletion sample-scripts/android_to_ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ iOS_EN="ios/Localizable/Base.lproj/Localizable.strings"
iOS_DE="ios/Localizable/de.lproj/Localizable.strings"
iOS_ES="ios/Localizable/es.lproj/Localizable.strings"

ANDROID_TO_iOS=( "--srcFormat=xml" "--targetFormat=ios-strings" "--service=sync-without-translate" "--keySearch=_" "--keyReplace=." )
ANDROID_TO_iOS=( "--srcFormat=xml" "--targetFormat=ios-strings" "--service=sync-without-translate" )

attranslate "${ANDROID_TO_iOS[@]}" --srcFile=$ANDROID_EN --targetFile=$iOS_EN --srcLng="en" --targetLng="en"
attranslate "${ANDROID_TO_iOS[@]}" --srcFile=$ANDROID_DE --targetFile=$iOS_DE --srcLng="de" --targetLng="de"
Expand Down
4 changes: 2 additions & 2 deletions sample-scripts/yaml_ecommerce.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ SERVICE_ACCOUNT_KEY="gcloud/gcloud_service_account.json"
COMMON_ARGS=( "--srcFile=yaml/en_ecommerce.yml" "--srcLng=en" "--srcFormat=yaml" "--targetFormat=yaml" "--service=manual" "--serviceConfig=$SERVICE_ACCOUNT_KEY" )

# Run "npm install --global attranslate" before you try this example.
attranslate "${COMMON_ARGS[@]}" --targetFile=yaml/es_ecommerce.yml --targetLng=es --keySearch="en\\." --keyReplace="es."
attranslate "${COMMON_ARGS[@]}" --targetFile=yaml/de_ecommerce.yml --targetLng=de --keySearch="en\\." --keyReplace="de."
attranslate "${COMMON_ARGS[@]}" --targetFile=yaml/es_ecommerce.yml --targetLng=es
attranslate "${COMMON_ARGS[@]}" --targetFile=yaml/de_ecommerce.yml --targetLng=de

# Convert a JSON to YML (just for the sake of test-coverage)
attranslate --srcFile="yaml/nested-fruits.json" --srcFormat=nested-json --srcLng=x --targetFile=yaml/nested-fruits.yml --targetFormat=yaml --targetLng=x --service=sync-without-translate
2 changes: 0 additions & 2 deletions src/core/core-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,4 @@ export interface CliArgs extends Record<string, string | undefined> {
service: string;
serviceConfig?: string;
matcher: string;
keySearch: string;
keyReplace: string;
}
3 changes: 1 addition & 2 deletions src/core/core-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ export async function readTFileCore(
const rawTSet = await module.readTFile(args);

const tSet: TSet = new Map();
const keyRegExp = new RegExp(args.keySearch, "g");
rawTSet.forEach((value, key) => {
const replacedKey = key.replace(keyRegExp, args.keyReplace);
const replacedKey = key;
tSet.set(replacedKey, value);
});
return tSet;
Expand Down
4 changes: 0 additions & 4 deletions src/core/translate-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ async function resolveOldTarget(
path: args.targetFile,
lng: args.targetLng,
format: targetFileFormat,
keySearch: args.keySearch,
keyReplace: args.keyReplace,
});
} else {
return null;
Expand Down Expand Up @@ -77,8 +75,6 @@ export async function translateCli(cliArgs: CliArgs) {
path: cliArgs.srcFile,
lng: cliArgs.srcLng,
format: srcFileFormat,
keySearch: cliArgs.keySearch,
keyReplace: cliArgs.keyReplace,
});
if (!src.size) {
logFatal(
Expand Down
2 changes: 0 additions & 2 deletions src/file-formats/file-format-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export interface ReadTFileArgs {
path: string;
lng: string;
format: TFileType;
keySearch: string;
keyReplace: string;
}

export interface TFileFormat {
Expand Down
12 changes: 0 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,6 @@ export function run(process: NodeJS.Process, cliBinDir: string): void {
formatOneOfOptions(getTMatcherList()),
"none"
)
.option(
"--keySearch <regExp>",
"A regular expression to replace translation-keys",
"x"
)
.option(
"--keyReplace <string>",
"The replacement for occurrences of keySearch",
"x"
)
.version(extractVersion({ cliBinDir }), "-v, --version")
.parse(process.argv);

Expand All @@ -83,8 +73,6 @@ export function run(process: NodeJS.Process, cliBinDir: string): void {
service: commander.opts().service,
serviceConfig: commander.opts().serviceConfig,
matcher: commander.opts().matcher,
keySearch: commander.opts().keySearch,
keyReplace: commander.opts().keyReplace,
};
translateCli(args)
.then(() => {
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/e2e-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ export const defaultE2EArgs: E2EArgs = {
service: "google-translate",
serviceConfig: "invalid-key",
matcher: "none",
keySearch: "x",
keyReplace: "x",
};

function getRandomTargetName(path: string) {
Expand Down
2 changes: 0 additions & 2 deletions test/file-formats/simple-read-write.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ describe.each(testArgs)("Read/write %p", (args) => {
path: args.srcFile,
lng: "en",
format: args.fileFormat,
keySearch: "x",
keyReplace: "x",
});

const expectTSetPath = `${args.srcFile}__expected_tset.json`;
Expand Down

0 comments on commit a95e9d2

Please sign in to comment.