Skip to content

Commit d4b5fe0

Browse files
committed
added autogenerated comments translations, closes #6
1 parent dd773d1 commit d4b5fe0

File tree

7 files changed

+64
-37
lines changed

7 files changed

+64
-37
lines changed

README.md

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ You can use `doxyjs` as standalone CLI tool to generate pseudo C++ code from jav
2929
Printing pseudo C++ representation of Javascript source to standard output:
3030

3131
```sh
32-
doxyqml --encoding utf8 --line-break lf file.js other_file.js
32+
doxyqml --encoding utf8 --line-break lf --lang ru file.js
3333
```
3434

3535
#### Options
@@ -39,17 +39,28 @@ $ doxyjs --help
3939

4040
Usage: doxyjs [options] [files...]
4141

42-
Converts Javascript into psudo C++ for Doxygen processing
42+
Converts Javascript into psudo C++ for Doxygen
4343

4444
Options:
4545

4646
-h, --help output usage information
4747
-V, --version output the version number
4848
-e, --encoding <encoding> source files encoding (utf8 by default)
4949
-b, --line-break <line break> line break symbol [lf|crlf] (lf by default)
50+
-l, --lang <language code> output language (en by default)
5051

5152
```
5253

54+
List of supported encodings can be found [here](https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings).
55+
56+
List of supported languages:
57+
58+
* de
59+
* en
60+
* es
61+
* it
62+
* ru
63+
5364
### Doxygen Integration
5465

5566
To use `doxyjs` with Doxygen you must make few changes to your Doxyfile.
@@ -146,9 +157,6 @@ Next contructions will be interpreted as classes:
146157
* @param type:Object arg argument description
147158
*/
148159
function Argument(arg) {
149-
if (!(this instanceof Argument)) {
150-
return new Argument(arg);
151-
}
152160
}
153161

154162
/*!
@@ -179,13 +187,6 @@ Argument.prototype.addArgument = function(arg) {
179187
* @param type:Object cmd command description
180188
*/
181189
function Command(cmd) {
182-
if (!(this instanceof Command)) {
183-
return new Command(cmd);
184-
}
185-
186-
var _cmd = (cmd || {});
187-
188-
Argument.call(this, _cmd);
189190
}
190191

191192
Command.prototype = Object.create(Argument.prototype);
@@ -196,13 +197,6 @@ Command.prototype.constructor = Argument;
196197
* @param type:Object event event description
197198
*/
198199
function Event(event) {
199-
if (!(this instanceof Event)) {
200-
return new Event(event);
201-
}
202-
203-
var _event = (event || {});
204-
205-
Argument.call(this, _event);
206200
}
207201

208202
Event.prototype = Object.create(Argument.prototype);

doxyjs.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const reduceToken = require('./src/reduceToken');
44
const tokenConverter = require('./src/tokenConverter.js');
55
const tokenExporter = require('./src/tokenExporter.js');
66

7-
const doxyjs = (input_data, encoding, linebreak) => {
7+
const doxyjs = (input_data, encoding, linebreak, ts) => {
88
const input_lines = input_data.split(linebreak).filter(line => line.length);
99
const input_file_tokens = input_lines.reduce(extractToken, []);
1010
const input_file_structure = input_file_tokens.reduce(reduceToken, {
@@ -24,14 +24,14 @@ const doxyjs = (input_data, encoding, linebreak) => {
2424
.map(tokenConverter.convertClass);
2525

2626
const exported_variables = global_variables.map(v =>
27-
tokenExporter.exportGlobalVariable(v, linebreak)
27+
tokenExporter.exportGlobalVariable(v, linebreak, ts)
2828
);
2929
const exported_functions = global_functions.map(f =>
30-
tokenExporter.exportGlobalFunction(f, linebreak)
30+
tokenExporter.exportGlobalFunction(f, linebreak, ts)
3131
);
3232

3333
const exported_classes = classes.map(c =>
34-
tokenExporter.exportClass(c, linebreak)
34+
tokenExporter.exportClass(c, linebreak, ts)
3535
);
3636

3737
process.stdout.write(
@@ -42,13 +42,13 @@ const doxyjs = (input_data, encoding, linebreak) => {
4242
);
4343
};
4444

45-
module.exports = (filename, encoding, linebreak) => {
45+
module.exports = (filename, encoding, linebreak, ts) => {
4646
fs.readFile(filename, encoding, (error, data) => {
4747
if (error) {
4848
console.error(`doxyjs: can't read file ${filename}, aborting`);
4949
process.exit(1);
5050
}
5151

52-
doxyjs(data, encoding, linebreak);
52+
doxyjs(data, encoding, linebreak, ts);
5353
});
5454
};

index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#!/usr/bin/env node
22

33
const program = require('commander');
4+
const localize = require('localize');
45
const doxyjs = require('./doxyjs');
56
const pkg = require('./package.json');
67

8+
const translator = new localize('./translations');
9+
710
program
811
.description(pkg.description)
912
.version(pkg.version)
@@ -18,6 +21,11 @@ program
1821
'line break symbol [lf|crlf] (lf by default)',
1922
val => (val.match(/^crlf$/i) ? '\r\n' : '\n'),
2023
'\n'
24+
)
25+
.option(
26+
'-l, --lang <language code>',
27+
'output language (en by default)',
28+
'en'
2129
);
2230

2331
program.parse(process.argv);
@@ -27,6 +35,8 @@ if (program.args.length == 0) {
2735
process.exit(1);
2836
}
2937

38+
translator.setLocale(program.lang);
39+
3040
program.args.forEach(file => {
31-
doxyjs(file, program.encoding, program.lineBreak);
41+
doxyjs(file, program.encoding, program.lineBreak, translator);
3242
});

package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "doxyjs",
33
"version": "1.0.3",
4-
"description": "Converts Javascript into psudo C++ for Doxygen processing",
4+
"description": "Converts Javascript into psudo C++ for Doxygen",
55
"main": "index.js",
66
"author": "Dmitry Toropchin",
77
"license": "MIT",
@@ -14,7 +14,11 @@
1414
"url": "https://github.com/dmitrytoropchin/doxyjs.git"
1515
},
1616
"dependencies": {
17-
"commander": "^2.9.0"
17+
"commander": "^2.9.0",
18+
"localize": "^0.4.7"
19+
},
20+
"devDependencies": {
21+
"jest": "^20.0.4"
1822
},
1923
"bin": {
2024
"doxyjs": "./index.js"
@@ -23,12 +27,10 @@
2327
"node": ">=7.0.0"
2428
},
2529
"keywords": [
26-
"cli", "doxygen"
30+
"cli",
31+
"doxygen"
2732
],
2833
"scripts": {
2934
"test": "jest"
30-
},
31-
"devDependencies": {
32-
"jest": "^20.0.4"
3335
}
3436
}

src/tokenExporter.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const exportGlobalVariable = (global_variable, linebreak) => {
1+
const exportGlobalVariable = (global_variable, linebreak, ts) => {
22
let variable_export = '';
33

44
if (global_variable.comment && global_variable.comment.brief) {
@@ -10,7 +10,7 @@ const exportGlobalVariable = (global_variable, linebreak) => {
1010
return variable_export;
1111
};
1212

13-
const exportGlobalFunction = (global_function, linebreak) => {
13+
const exportGlobalFunction = (global_function, linebreak, ts) => {
1414
let function_export = '';
1515

1616
if (global_function.comment) {
@@ -45,7 +45,7 @@ const exportGlobalFunction = (global_function, linebreak) => {
4545
return function_export;
4646
};
4747

48-
const exportClass = (_class, linebreak) => {
48+
const exportClass = (_class, linebreak, ts) => {
4949
let class_export = '';
5050

5151
if (_class.constructor && _class.constructor.comment) {
@@ -66,7 +66,9 @@ const exportClass = (_class, linebreak) => {
6666
const comment = _class.constructor.comment;
6767

6868
class_export += `/*!${linebreak}`;
69-
class_export += ` * @brief Constructor${linebreak}`;
69+
class_export += ` * @brief ${ts
70+
? ts.translate('Constructor')
71+
: 'Constructor'}${linebreak}`;
7072

7173
if (comment.params) {
7274
Object.keys(comment.params)
@@ -86,7 +88,7 @@ const exportClass = (_class, linebreak) => {
8688
}
8789

8890
_class.methods.forEach(method => {
89-
class_export += `${exportGlobalFunction(method, linebreak)}`;
91+
class_export += `${exportGlobalFunction(method, linebreak, ts)}`;
9092
});
9193

9294
class_export += `};${linebreak}`;

translations/translations.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Constructor": {
3+
"de": "Konstrukteur",
4+
"en": "Constructor",
5+
"es": "Constructor",
6+
"it": "Costruttore",
7+
"ru": "Конструктор"
8+
}
9+
}

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,10 @@ commander@^2.9.0:
404404
dependencies:
405405
graceful-readlink ">= 1.0.0"
406406

407+
commander@~2.1.0:
408+
version "2.1.0"
409+
resolved "https://registry.yarnpkg.com/commander/-/commander-2.1.0.tgz#d121bbae860d9992a3d517ba96f56588e47c6781"
410+
407411
408412
version "0.0.1"
409413
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
@@ -1264,6 +1268,12 @@ load-json-file@^1.0.0:
12641268
pinkie-promise "^2.0.0"
12651269
strip-bom "^2.0.0"
12661270

1271+
localize@^0.4.7:
1272+
version "0.4.7"
1273+
resolved "https://registry.yarnpkg.com/localize/-/localize-0.4.7.tgz#e3b69e5ac1ee47fe211ff07a02b8f2e969bf9cfa"
1274+
dependencies:
1275+
commander "~2.1.0"
1276+
12671277
locate-path@^2.0.0:
12681278
version "2.0.0"
12691279
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e"

0 commit comments

Comments
 (0)