diff --git a/README.md b/README.md index 4d7f119..e5ecebd 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ jsontt logo

-#

**🚀 FREE JSON/YAML TRANSLATOR 🆓**

+#

**🚀 FREE JSON/YAML/PROPERTIES TRANSLATOR 🆓**

@@ -22,7 +22,7 @@

-This package will provide you to translate your JSON/YAML files or JSON objects into different languages FREE. +This package will provide you to translate your JSON/YAML/PROPERTIES files or JSON objects into different languages FREE. ### Types of usages 👀 @@ -54,6 +54,8 @@ npm i -g @parvineyvazov/json-translator jsontt or jsontt +or +jsontt ``` ## How to use it? (video below) @@ -62,7 +64,7 @@ jsontt ## Arguments -- `[path]`: Required JSON/YAML file path `` +- `[path]`: Required JSON/YAML/PROPERTIES file path `` - `[path]`: optional proxy list txt file path `` ## Options @@ -108,7 +110,7 @@ jsontt --module google --from en --to ar fr zh-CN --nam ### other usage examples -- translate (json/yaml) +- translate (json/yaml/properties) ```bash jsontt file.json @@ -132,7 +134,7 @@ jsontt "C:\folder1\folder\en.json" jsontt file.json proxy.txt ``` -Result will be in the same folder as the original JSON/YAML file. +Result will be in the same folder as the original JSON/YAML/PROPERTIES file.
diff --git a/package.json b/package.json index 8a8be66..e49592f 100644 --- a/package.json +++ b/package.json @@ -89,6 +89,7 @@ "http-proxy-agent": "^5.0.0", "inquirer": "^7.0.0", "loading-cli": "^1.1.0", - "yaml": "^2.3.2" + "yaml": "^2.3.2", + "properties": "^1.2.1" } } diff --git a/src/core/core.ts b/src/core/core.ts index 83daff2..b257afb 100644 --- a/src/core/core.ts +++ b/src/core/core.ts @@ -1,7 +1,9 @@ import * as fs from 'fs/promises'; import * as YAML from 'yaml'; import { matchYamlExt } from '../utils/yaml'; +import { isPropertiesExt } from '../utils/properties'; import { error, messages } from '../utils/console'; +import * as properties from 'properties'; export async function getFile(objectPath: string) { let json_file: any = undefined; @@ -14,7 +16,7 @@ export async function getFile(objectPath: string) { // and then stringified to JSON string. json_file = matchYamlExt(objectPath) ? JSON.stringify(YAML.parse(data)) - : data; + : (isPropertiesExt(objectPath) ? JSON.stringify(properties.parse(data,null,null)) : data); }) .catch(_ => { json_file = undefined; @@ -39,7 +41,7 @@ export function getRootFolder(path: string) { export async function saveFilePublic(path: string, data: any) { // When path extension is for YAML file, then stringify with YAML encoder. // Otherwise, default JSON encoder is used. - var json = matchYamlExt(path) ? YAML.stringify(data) : JSON.stringify(data); + var json = matchYamlExt(path) ? YAML.stringify(data) : (isPropertiesExt(path) ? properties.stringify(data,null,null) : JSON.stringify(data)); await fs .writeFile(path, json, 'utf8') diff --git a/src/core/json_file.ts b/src/core/json_file.ts index 44a6bdf..78bca09 100644 --- a/src/core/json_file.ts +++ b/src/core/json_file.ts @@ -5,6 +5,7 @@ import { objectTranslator } from './json_object'; import { matchYamlExt } from '../utils/yaml'; import { TranslationConfig } from '../modules/modules'; import { getLanguageKeyFromValue } from '../modules/helpers'; +import {isPropertiesExt} from "../utils/properties"; export async function fileTranslator( TranslationConfig: TranslationConfig, @@ -68,6 +69,8 @@ export async function getFileFromPath( } function getFileExt(latestPath: string): string { + // We also check properties here. + if(isPropertiesExt(latestPath)) return 'properties'; // Check if source file has YAML extension and return the extension ("yml" or "yaml"). const sourceFileMatchYamlExt = matchYamlExt(latestPath); diff --git a/src/properties.d.ts b/src/properties.d.ts new file mode 100644 index 0000000..abd3046 --- /dev/null +++ b/src/properties.d.ts @@ -0,0 +1,8 @@ +declare module 'properties' { + export function createStringifier(): any; + + export function parse(data: any, options: any, cb: any): any; + + export function stringify(stringifier: any, options: any, cb: any): any; +} + diff --git a/src/utils/properties.ts b/src/utils/properties.ts new file mode 100644 index 0000000..e55ff51 --- /dev/null +++ b/src/utils/properties.ts @@ -0,0 +1,7 @@ +/** + * + * @param objectPath path to file + * @returns File extension without leading "." ("properties" ) + */ +export const isPropertiesExt = (objectPath: string) => + objectPath.endsWith(".properties") diff --git a/yarn.lock b/yarn.lock index 793dd2e..c333b35 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6053,6 +6053,11 @@ propagate@^2.0.0: resolved "https://registry.npmjs.org/propagate/-/propagate-2.0.1.tgz#40cdedab18085c792334e64f0ac17256d38f9a45" integrity sha512-vGrhOavPSTz4QVNuBNdcNXePNdNMaO1xj9yBeH1ScQPjk/rhg9sSlCXPhMkFuaNNW/syTvYqsnbIJxMBfRbbag== +properties@^1.2.1: + version "1.2.1" + resolved "https://registry.npmmirror.com/properties/-/properties-1.2.1.tgz#0ee97a7fc020b1a2a55b8659eda4aa8d869094bd" + integrity sha512-qYNxyMj1JeW54i/EWEFsM1cVwxJbtgPp8+0Wg9XjNaK6VE/c4oRi6PNu5p7w1mNXEIQIjV5Wwn8v8Gz82/QzdQ== + proxy-from-env@^1.1.0: version "1.1.0" resolved "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz"