Skip to content

Commit

Permalink
Add docs about logger of missing keys (#282)
Browse files Browse the repository at this point in the history
* Add docs about logger of missing keys

* Update deps
  • Loading branch information
aralroca authored Oct 23, 2020
1 parent a71ac42 commit c2b3d3b
Show file tree
Hide file tree
Showing 3 changed files with 933 additions and 783 deletions.
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ In your **package.json**:

You should create your namespaces files inside `/locales`. [See how to do it](#3-translation-jsons-folder)

Add a configuration file `i18n.json` in the root of the project. Each page should have its namespaces. Take a look at it in the [config](#4-configuration) section for more details.
Add a configuration file `i18n.json` _(or `i18n.js` with `module.exports`)_ in the root of the project. Each page should have its namespaces. Take a look at it in the [config](#4-configuration) section for more details.

```json
{
Expand Down Expand Up @@ -213,18 +213,19 @@ In order to use each translation in the project, use the _translation id_ compos

## 4. Configuration

| Option | Description | Type | Default |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------- | -------------------------------------------------------------------------- |
| `defaultLanguage` | ISO of the default locale ("en" as default). | `string\|function` | `"en"` |
| `allLanguages` | An array with all the languages to use in the project. | `Array<string>` | `[]` |
| `ignoreRoutes` | An array with all the routes to ignore in the middleware. This config property only effects using the `i18nMiddleware`, SO MAYBE YOU'LL NEVER NEED THIS. | `Array<string>` | `['/_next/', '/static/', '/favicon.ico', '/manifest.json', '/robots.txt']` |
| `defaultLangRedirect` | It accepts `lang-path` and `root` as string. If it's set to `lang-path` redirects the default language routes from `/my-route` to `/en/my-route`. If it's set to `root` redirects the default language routes from `/en/my-route` to `/my-route`. Otherwise, when it's not defined, it's not doing any redirect (default). | `string\|undefined` | undefined |
| `currentPagesDir` | A string with the directory where you have the pages code. This is needed for the "build step". | `string` | `"pages_"` |
| `finalPagesDir` | A string with the directory that is going to be used to build the pages. Only "pages" and "src/pages" are possible. This is needed for the "build step". | `string` | `"pages"` |
| `localesPath` | A string with the directory of JSONs locales. This is needed for the "build step". | `string` | `"locales"` |
| `loadLocaleFrom` | As an alternative to `localesPath`, if `i18nMiddleware` is used instead of the "build step". It's an async function that returns the dynamic import of each locale. [See an example](/docs/USING_CUSTOM_SERVER.md#3-add-the-i18n-middleware) | `Function` | `null` |
| `pages` | An object that defines the namespaces used in each page. Example of object: `{"/": ["home", "example"]}`. To add namespaces to all pages you should use the key `"*"`, ex: `{"*": ["common"]}`. It's also possible to use regex using `rgx:` on front: `{"rgx:/form$": ["form"]}`. In case of using a custom server as an [alternative](#using-an-alternative-of-the-build-step-custom-server) of the "build step", you can also use a function instead of an array, to provide some namespaces depending on some rules, ex: `{ "/": ({ req, query }) => query.type === 'example' ? ['example'] : []}` | `Object<Array<string>/Function` | `{}` |
| `logBuild` | Configure if the build result should be logged to the console | `Boolean` | `true` |
| Option | Description | Type | Default |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------- | ------------------------------------------------------------------------------- |
| `defaultLanguage` | ISO of the default locale ("en" as default). | `string\|function` | `"en"` |
| `allLanguages` | An array with all the languages to use in the project. | `Array<string>` | `[]` |
| `ignoreRoutes` | An array with all the routes to ignore in the middleware. This config property only effects using the `i18nMiddleware`, SO MAYBE YOU'LL NEVER NEED THIS. | `Array<string>` | `['/_next/', '/static/', '/favicon.ico', '/manifest.json', '/robots.txt']` |
| `defaultLangRedirect` | It accepts `lang-path` and `root` as string. If it's set to `lang-path` redirects the default language routes from `/my-route` to `/en/my-route`. If it's set to `root` redirects the default language routes from `/en/my-route` to `/my-route`. Otherwise, when it's not defined, it's not doing any redirect (default). | `string\|undefined` | undefined |
| `currentPagesDir` | A string with the directory where you have the pages code. This is needed for the "build step". | `string` | `"pages_"` |
| `finalPagesDir` | A string with the directory that is going to be used to build the pages. Only "pages" and "src/pages" are possible. This is needed for the "build step". | `string` | `"pages"` |
| `localesPath` | A string with the directory of JSONs locales. This is needed for the "build step". | `string` | `"locales"` |
| `loadLocaleFrom` | As an alternative to `localesPath`, if `i18nMiddleware` is used instead of the "build step". It's an async function that returns the dynamic import of each locale. [See an example](/docs/USING_CUSTOM_SERVER.md#3-add-the-i18n-middleware) | `Function` | `null` |
| `pages` | An object that defines the namespaces used in each page. Example of object: `{"/": ["home", "example"]}`. To add namespaces to all pages you should use the key `"*"`, ex: `{"*": ["common"]}`. It's also possible to use regex using `rgx:` on front: `{"rgx:/form$": ["form"]}`. In case of using a custom server as an [alternative](#using-an-alternative-of-the-build-step-custom-server) of the "build step", you can also use a function instead of an array, to provide some namespaces depending on some rules, ex: `{ "/": ({ req, query }) => query.type === 'example' ? ['example'] : []}` | `Object<Array<string>/Function` | `{}` |
| `logger` | Function to log the **missing keys** in development and production. If you are using `i18n.json` as config file you should change it to `i18n.js`. | `function` | By default the logger is a function doing a `console.warn` only in development. | |
| `logBuild` | Configure if the build result should be logged to the console | `Boolean` | `true` |

## 5. API

Expand Down Expand Up @@ -567,7 +568,7 @@ export default class MyDocument extends Document {

- **Props**:
- `props` - Object - the document properties
- `i18nConfig` - Object - i18n config. Is optional. By default is using the config from `/i18n.json` file.
- `i18nConfig` - Object - i18n config. Is optional. By default is using the config from `/i18n.js` or `/i18n.json` file.

## 6. Plurals

Expand Down Expand Up @@ -869,6 +870,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d

<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
Loading

0 comments on commit c2b3d3b

Please sign in to comment.