@@ -62,4 +62,136 @@ Also, below is the list of example result files of such translation.
6262English (source) | Korean | Japanese | Arabic
6363--------|--------|----------|--------
6464[ bbs.article.json] ( https://github.com/samchon/json-translator/blob/master/assets/input/bbs.article.json ) | [ bbs.ko.json] ( https://github.com/samchon/json-translator/blob/master/assets/output/bbs.article.ko.json ) | [ bbs.ja.json] ( https://github.com/samchon/json-translator/blob/master/assets/output/bbs.article.ja.json ) | [ bbs.ar.json] ( https://github.com/samchon/json-translator/blob/master/assets/output/bbs.article.ar.json )
65- [ shopping.swagger.json] ( https://github.com/samchon/json-translator/blob/master/assets/input/shopping.swagger.json ) | [ shopping.ko.json] ( https://github.com/samchon/json-translator/blob/master/assets/output/shopping.swagger.ko.json ) | [ shopping.ja.json] ( https://github.com/samchon/json-translator/blob/master/assets/output/shopping.swagger.ja.json ) | [ shopping.ar.json] ( https://github.com/samchon/json-translator/blob/master/assets/output/shopping.swagger.ar.json )
65+ [ shopping.swagger.json] ( https://github.com/samchon/json-translator/blob/master/assets/input/shopping.swagger.json ) | [ shopping.ko.json] ( https://github.com/samchon/json-translator/blob/master/assets/output/shopping.swagger.ko.json ) | [ shopping.ja.json] ( https://github.com/samchon/json-translator/blob/master/assets/output/shopping.swagger.ja.json ) | [ shopping.ar.json] ( https://github.com/samchon/json-translator/blob/master/assets/output/shopping.swagger.ar.json )
66+
67+
68+
69+
70+ ## API
71+ ``` typescript
72+ export class JsonTranslator {
73+ /**
74+ * Translate JSON data.
75+ *
76+ * `JsonTranslate.translate()` translates JSON input data into another language.
77+ *
78+ * If you want to filter some specific values to translate, fill the
79+ * {@link JsonTranslator.IProps.filter } function.
80+ *
81+ * Also, if you do not fill the {@link JsonTranslator.IProps.source } value,
82+ * the source language would be detected through the {@link JsonTranslator.detect }
83+ * method with the longest text. Otherwise you assign the `null` value to the
84+ * {@link JsonTranslator.IProps.source } , the translation would be executed without
85+ * the source language.
86+ *
87+ * @template T The type of the JSON input data.
88+ * @param props Properties for the translation.
89+ * @returns The translated JSON data.
90+ */
91+ public translate<T >(props : JsonTranslator .IProps <T >): Promise <T >;
92+
93+ /**
94+ * Detect the language of JSON data.
95+ *
96+ * Pick the longest text from the JSON input data and detect the language
97+ * through the Google Translate API, with the similar properties like the
98+ * {@link JsonTranslator.translate } method.
99+ *
100+ * Therefore, if you want to filter some specific values to participate in
101+ * the language detection, fill the {@link JsonTranslator.IProps.filter }
102+ * function.
103+ *
104+ * @param input Properties for language detection.
105+ * @returns The detected language or `undefined` if the language is unknown.
106+ */
107+ public detect<T >(
108+ props : Omit <JsonTranslator .IProps <T >, " source" | " target" >,
109+ ): Promise <string | undefined >;
110+ }
111+ export namespace JsonTranslator {
112+ /**
113+ * Properties for the translation.
114+ */
115+ export interface IProps <T > {
116+ /**
117+ * The JSON input data to translate.
118+ */
119+ input: T ;
120+
121+ /**
122+ * Source language code.
123+ *
124+ * If not specified (`undefined`), the source language would be detected
125+ * through the {@link JsonTranslator.detect } method with the longest text.
126+ *
127+ * Otherwise `null` value assigned, the source language would be skipped,
128+ * so that the translation would be executed without the source language.
129+ * Therefore, if your JSON value contains multiple languages, you should
130+ * assign the `null` value to prevent the source language specification.
131+ */
132+ source? : string | null | undefined ;
133+
134+ /**
135+ * Target language code.
136+ */
137+ target: string ;
138+
139+ /**
140+ * Filter function specifying which data to translate.
141+ *
142+ * @param explore Information about the data to explore.
143+ * @returns `true` if the data should be translated; otherwise, `false`.
144+ */
145+ filter? : ((explore : IExplore ) => boolean ) | null | undefined ;
146+
147+ /**
148+ * Reserved dictionary of pre-translated values.
149+ *
150+ * The dictionary is a key-value pair object containing the pre-translated
151+ * values. The key means the original value, and the value means the
152+ * pre-translated value.
153+ *
154+ * If this dictionary has been configured and a JSON input value matches to
155+ * the dictionary's key, the dictionary's value would be used instead of
156+ * calling the Google Translate API.
157+ */
158+ dictionary? : Record <string , string > | null | undefined ;
159+ }
160+
161+ /**
162+ * Exploration information used in the {@link IProps.filter } function.
163+ */
164+ export interface IExplore {
165+ /**
166+ * The parent object instance.
167+ */
168+ object: object | null ;
169+
170+ /**
171+ * The property key containing the {@link value }
172+ */
173+ key: string | null ;
174+
175+ /**
176+ * Index number if the {@link value } is an array element.
177+ */
178+ index: number | null ;
179+
180+ /**
181+ * Accessor path to the {@link value } .
182+ *
183+ * It starts from the `["$input"]` array value, and each element
184+ * would be the property key or the index number.
185+ *
186+ * For example, if there's an access expression `$input.a[0].b`,
187+ * the accessor would be `["$input", "a", "0", "b"]`.
188+ */
189+ accessor: string [];
190+
191+ /**
192+ * The string value to translate.
193+ */
194+ value: string ;
195+ }
196+ }
197+ ```
0 commit comments