Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Editing i18n name on docs #54

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ There are a lot of things that you could do to collaborate on open sources proje

#### Create a new issue

If you spot any problem while using the project, see any error on the doc, or just wants to suggest changes to improve the project you can [create a new issue](https://github.com/victor-heliomar/i18n-translation-generator/issues/new/choose). Please make sure of check first that the issue doesn't exists already exists on the [issues list](https://github.com/victor-heliomar/i18n-translation-generator/issues).
If you spot any problem while using the project, see any error on the doc, or just wants to suggest changes to improve the project you can [create a new issue](https://github.com/victor-heliomar/i18n-populator/issues/new/choose). Please make sure of check first that the issue doesn't exists already exists on the [issues list](https://github.com/victor-heliomar/i18n-populator/issues).

#### Solve an issue

Scan through our existing issues to find one that interests you. If you find an issue to work on, you can leave a comment on the issue to leave us know that you're working on it and when you had developed your solution you can open a PR with a fix.

#### Help to solve the community doubts

If there is any doubt on any issue and you think you can help to solve it, then feel free to help to clear the doubts through the comments box of the issue selected, always following our [CODE OF CONDUCTS](https://github.com/victor-heliomar/i18n-translation-generator/blob/dev/CODE_OF_CONDUCT.md).
If there is any doubt on any issue and you think you can help to solve it, then feel free to help to clear the doubts through the comments box of the issue selected, always following our [CODE OF CONDUCTS](https://github.com/victor-heliomar/i18n-populator/blob/dev/CODE_OF_CONDUCT.md).

### Making changes

Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# i18n translate generator
# i18n populator

Generate translations for all your i18n jsons with only one terminal command.

![i18n translations (1)](https://github.com/victor-heliomar/i18n-translation-generator/assets/66505715/2566afc9-7120-466c-b9e5-4301e32bd64d)
![i18n translations (1)](https://github.com/victor-heliomar/i18n-populator/assets/66505715/2566afc9-7120-466c-b9e5-4301e32bd64d)

This project uses [LibreTranslate](https://github.com/LibreTranslate/LibreTranslate), [Google Translate API](https://github.com/vitalets/google-translate-api) and [Bing Translate API](https://github.com/plainheart/bing-translate-api) to generate the translations. In a future I'll include the option to use an Google API Key / Bing Api Key so you could use it with your own account.

Expand Down Expand Up @@ -55,7 +55,7 @@ Init command will start a wizard to help you to create the configuration file fo
npx i18n-populator init
```

Anyway, if you want to create the configuration file manually, you can create a i18n-auto-translate.config.json on the root of your project and continue reading the next section.
Anyway, if you want to create the configuration file manually, you can create a i18n-populator.config.json on the root of your project and continue reading the next section.

### Configuration file

Expand All @@ -81,7 +81,7 @@ Anyway, if you want to create the configuration file manually, you can create a

```

Also you can check an example on [configuration file](./i18n-auto-translate.config.json)
Also you can check an example on [configuration file](./i18n-populator.config.json)

2. In order to translate, you need to run the `translate` command, write the phrase you want to translate and select the source language that it is wrote in, and at the end add a name for your new translation, this will be used on your json files as property name.

Expand All @@ -99,7 +99,7 @@ npx i18n-populator translate "Hola mundo" "es" "greetings"

You only need to specify in what language is wrote the text that you're passing through command, since all the languages that you want to translate are specified on the configuration file.

Also, additionally you can specify the path of the configuration file, by default it will search for the file called `i18n-auto-translate.config.json` on the root of your project, but you can specify another path with the `-s` or `--settings-file` flag.
Also, additionally you can specify the path of the configuration file, by default it will search for the file called `i18n-populator.config.json` on the root of your project, but you can specify another path with the `-s` or `--settings-file` flag.

For example

Expand Down Expand Up @@ -228,7 +228,7 @@ The configuration file is an json file which allow you to modify certain aspects

| Command | Description | Arguments | Options | Example |
| --- | --- | --- | --- | --- |
| `translate` | Translate a text to all the languages that you're handling on your project. | `text`: The word or sentence that you want to translate. `sourceLanguage`: The language of the text that you wrote on `text`.`propertyName`: The property name that you want to be used to include your new translation on your project | `--engine, -e`: The translation engine that you want to use. `--settings-file, -s`: Custom path for the settings file. Default is "i18n-auto-translate.config.json" | `npx i18n-auto-translate translate "my text" "en" "myText"` |
| `help` | Show the help menu with all the available commands. | | | `npx i18n-auto-translate help` |
| `languages` | Show the supported languages of all the engines or filter it by engines. | | `--by-engine, -be`: Filter the supported languages by engine. | `npx i18n-auto-translate languages` |
| `init` | Start the configuration wizard to create the settings file | | | `npx i18n-auto-translate init` |
| `translate` | Translate a text to all the languages that you're handling on your project. | `text`: The word or sentence that you want to translate. `sourceLanguage`: The language of the text that you wrote on `text`.`propertyName`: The property name that you want to be used to include your new translation on your project | `--engine, -e`: The translation engine that you want to use. `--settings-file, -s`: Custom path for the settings file. Default is "i18n-populator.config.json" | `npx i18n-populator translate "my text" "en" "myText"` |
| `help` | Show the help menu with all the available commands. | | | `npx i18n-populator help` |
| `languages` | Show the supported languages of all the engines or filter it by engines. | | `--by-engine, -be`: Filter the supported languages by engine. | `npx i18n-populator languages` |
| `init` | Start the configuration wizard to create the settings file | | | `npx i18n-populator init` |
2 changes: 1 addition & 1 deletion config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const config = {
defaultConfigPath: 'i18n-auto-translate.config.json'
defaultConfigPath: 'i18n-populator.config.json'
}

module.exports = config
6 changes: 3 additions & 3 deletions controllers/generateConfigController.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const _promptLanguages = (filesNames) => {
"We'll iterate over the files in the base path and you will be able to select the language name for each file.\n"
);
console.log(
"The language should be indicated in ISO 639-1 format. For example: 'English' -> 'en'. You can consult the file https://github.com/victor-heliomar/i18n-translation-generator/blob/dev/ALL-LANGUAGES-CODES.json to get all the codes or check here: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes\n"
"The language should be indicated in ISO 639-1 format. For example: 'English' -> 'en'. You can consult the file https://github.com/victor-heliomar/i18n-populator/blob/dev/ALL-LANGUAGES-CODES.json to get all the codes or check here: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes\n"
);
console.log("Leave it empty if you don't want to include that file.\n");
console.log(
Expand Down Expand Up @@ -124,7 +124,7 @@ const _promptLanguages = (filesNames) => {
console.log(
`The language ${languageName} is not supported. Please use one of these: ${supportedLanguagesCodes.join(
", "
)}. Detailed information on https://github.com/victor-heliomar/i18n-translation-generator/blob/dev/ALL-LANGUAGES-CODES.json\n\n`
)}. Detailed information on https://github.com/victor-heliomar/i18n-populator/blob/dev/ALL-LANGUAGES-CODES.json\n\n`
);
promptUserInput("Press enter to continue...\n");
}
Expand Down Expand Up @@ -157,7 +157,7 @@ const _promptLanguages = (filesNames) => {
};

const generateConfigController = async () => {
const configPath = parsePath("/i18n-auto-translate.config.json");
const configPath = parsePath("/i18n-populator.config.json");
const configExists = fs.existsSync(configPath);

if (configExists) {
Expand Down
6 changes: 3 additions & 3 deletions controllers/generateConfigController.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ describe("generateConfigController", () => {
});

it("should overwrite the configuration file if it already exists and user confirms", async () => {
const configPath = parsePath("/i18n-auto-translate.config.json");
const configPath = parsePath("/i18n-populator.config.json");
const basePath = "test-configs/translations"
const pathFiles = ["english-file.json", "spanish-file.json"];

Expand Down Expand Up @@ -303,7 +303,7 @@ describe("generateConfigController", () => {
});

it("should cancel the wizard if the configuration file already exists and user does not confirm", async () => {
const configPath = parsePath("/i18n-auto-translate.config.json");
const configPath = parsePath("/i18n-populator.config.json");

fs.existsSync.mockReturnValueOnce(true);
confirmUserAction.mockReturnValueOnce(false);
Expand All @@ -326,7 +326,7 @@ describe("generateConfigController", () => {
});

it("should create a new configuration file if it does not exist", async () => {
const configPath = parsePath("/i18n-auto-translate.config.json");
const configPath = parsePath("/i18n-populator.config.json");
const userSelectedBasePath = "test-configs/translations";
const filesNames = ["english.json", "spanish.json"];

Expand Down
42 changes: 0 additions & 42 deletions i18n-auto-translate.config.json

This file was deleted.

22 changes: 22 additions & 0 deletions i18n-populator.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"basePath": "example",
"translationEngines": [
"google",
"bing",
"libreTranslate"
],
"languages": [
{
"name": "en",
"files": [
"en.json"
]
},
{
"name": "es",
"files": [
"es.json"
]
}
]
}
2 changes: 1 addition & 1 deletion services/translateService.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const setTranslateWithFallbackEngines = ({
const enginesUsed = engines.join(", ");

throw new Error(
`Error translating ${text} from ${from} to ${to} using ${enginesUsed}.\n\nPlease check that requested languages is supported using the command "languages" or check your internet connection and try again.\n\nFor more info check CLI help or open an issue at https://github.com/victor-heliomar/i18n-translation-generator/issues/new`
`Error translating ${text} from ${from} to ${to} using ${enginesUsed}.\n\nPlease check that requested languages is supported using the command "languages" or check your internet connection and try again.\n\nFor more info check CLI help or open an issue at https://github.com/victor-heliomar/i18n-populator/issues/new`
);
}

Expand Down
15 changes: 13 additions & 2 deletions utils/getOrCreateJsonFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@ const getOrCreateJsonFile = (basePath, fileName) => {
const parsedPath = parsePath(`${basePath}/${fileName}`);

if (fs.existsSync(parsedPath)) {
const file = require(parsedPath);
return { file, parsedPath };
try {
const file = require(parsedPath);
return { file, parsedPath };
} catch (error) {
console.error(`Error reading file ${parsedPath}.`);

if (error instanceof SyntaxError) {
console.error('Syntax error in JSON file. It is probably malformed.');
console.error('It exists and is on your i18n-populator.config.js file but it is not a valid JSON file.');
}

process.exit(1);
}
}

const file = {};
Expand Down
Loading