Skip to content

Commit

Permalink
feat: add prettier workflow (#2111)
Browse files Browse the repository at this point in the history
* feat: add prettier workflow

* delete overrides
  • Loading branch information
Abdel-Monaam-Aouini authored Mar 9, 2023
1 parent d68f7be commit f538618
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 52 deletions.
19 changes: 9 additions & 10 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@

# Number of days of inactivity before an issue becomes stale
daysUntilStale: 7
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7
# Issues with these labels will never be considered stale
exemptLabels:
- "discussion"
- "feature request"
- "bug"
- "breaking change"
- "doc"
- "issue"
- "help wanted"
- "good first issue"
- "pr hold"
- 'discussion'
- 'feature request'
- 'bug'
- 'breaking change'
- 'doc'
- 'issue'
- 'help wanted'
- 'good first issue'
- 'pr hold'
# Label to use when marking an issue as stale
staleLabel: stale
# Comment to post when marking an issue as stale. Set to `false` to disable
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ jobs:
- name: Typecheck
run: npm run typecheck

- name: Prettier
run: npm run prettier

- name: Unit tests
run: npm test

Expand Down
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
If you're experiencing typecheck errors regarding keys: ensure `i18next` is at least `^22.4.3` in your
package.json (then run install), see [#2058](https://github.com/i18next/next-i18next/pull/2058).


## 13.0.0

The v13.0.0 release is a major version to improve stability and general experience.
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ module.exports = {
typeof window === 'undefined'
? require('path').resolve('./my-custom/path')
: '/public/my-custom/path',
ns: ['common']
ns: ['common'],
}
```

Expand Down Expand Up @@ -339,6 +339,7 @@ For example, if you want to use `{` and `}` the config would look like this:
If you want to change the default config path, you can set the environment variable `I18NEXT_DEFAULT_CONFIG_PATH`.

For example, inside the `.env` file you can set a static path:

```
I18NEXT_DEFAULT_CONFIG_PATH=/path/to/project/apps/my-app/next-i18next.config.js
```
Expand Down Expand Up @@ -403,7 +404,6 @@ But there's a way to workaround that with the help of [next-language-detector](h
Check out [this blog post](https://locize.com/blog/next-i18n-static/) and [this example project](./examples/ssg/).
[![](https://locize.com/blog/next-i18n-static/title.jpg)](https://locize.com/blog/next-i18n-static/)


### Translate in child components

You have multiple ways to use the t function in your child component:
Expand All @@ -413,7 +413,7 @@ You have multiple ways to use the t function in your child component:
3. Use the [`useTranslation`](https://react.i18next.com/latest/usetranslation-hook) function, like in this example: https://github.com/i18next/next-i18next/blob/e6b5085b5e92004afa9516bd444b19b2c8cf5758/examples/simple/components/Footer.tsx#L6
4. Use the [`withTranslation`](https://react.i18next.com/latest/withtranslation-hoc) function

*And in general, you always needs to be sure serverSideTranslations contains all namespaces you need in the tree.*
_And in general, you always needs to be sure serverSideTranslations contains all namespaces you need in the tree._

## Contributors

Expand Down
2 changes: 1 addition & 1 deletion examples/simple/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const Footer: FC = () => {
}}
>
<Trans i18nKey="helpLocize" t={t}>
With using
With using
<a href="https://locize.com" target="_new">
locize
</a>
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Homepage = (
</h3>
<p>
<Trans i18nKey="blog.appDir.answer">
Then check out
Then check out
<a href={t('blog.optimized.link')}>this blog post</a>
.
</Trans>
Expand Down
34 changes: 15 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"locale"
],
"scripts": {
"prettier": "prettier --ignore-path .gitignore --write .",
"lint": "eslint src examples",
"clean": "rm -rf ./examples/simple/.next ./examples/ssg/.next ./dist && mkdir dist",
"build:es": "BABEL_ENV=es babel src --extensions '.ts,.tsx' --out-dir dist/es --copy-files",
Expand Down
10 changes: 5 additions & 5 deletions prettier.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

module.exports = {
// These settings are duplicated in .editorconfig:
tabWidth: 2, // indent_size = 2
useTabs: false, // indent_style = space
arrowParens: 'avoid',
bracketSpacing: true,
endOfLine: 'lf', // end_of_line = lf
printWidth: 69, // default: 80
semi: false, // default: true
singleQuote: true, // default: false
printWidth: 69, // default: 80
tabWidth: 2, // indent_size = 2
trailingComma: 'es5',
bracketSpacing: true,
arrowParens: 'avoid',
useTabs: false, // indent_style = space
}
20 changes: 13 additions & 7 deletions src/config/createConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ export const createConfig = (
[combinedConfig.fallbackLng] = locales
}

const userPrefix = userConfig?.interpolation?.prefix;
const userSuffix = userConfig?.interpolation?.suffix;
const prefix = userPrefix ?? '{{';
const suffix = userSuffix ?? '}}';
if (typeof userConfig?.localeStructure !== 'string' && (userPrefix || userSuffix)) {
combinedConfig.localeStructure = `${prefix}lng${suffix}/${prefix}ns${suffix}`;
const userPrefix = userConfig?.interpolation?.prefix
const userSuffix = userConfig?.interpolation?.suffix
const prefix = userPrefix ?? '{{'
const suffix = userSuffix ?? '}}'
if (
typeof userConfig?.localeStructure !== 'string' &&
(userPrefix || userSuffix)
) {
combinedConfig.localeStructure = `${prefix}lng${suffix}/${prefix}ns${suffix}`
}

const { fallbackLng, localeStructure } = combinedConfig
Expand Down Expand Up @@ -233,7 +236,10 @@ export const createConfig = (
return unique(allNamespaces)
}

if (localeStructure.indexOf(`${prefix}lng${suffix}`) > localeStructure.indexOf(`${prefix}ns${suffix}`)) {
if (
localeStructure.indexOf(`${prefix}lng${suffix}`) >
localeStructure.indexOf(`${prefix}ns${suffix}`)
) {
throw new Error(
'Must provide all namespaces in ns option if using a localeStructure that is not namespace-listable like lng/ns'
)
Expand Down
9 changes: 4 additions & 5 deletions src/serverSideTranslations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@ export const serverSideTranslations = async (
let userConfig = configOverride
const configPath = path.resolve(DEFAULT_CONFIG_PATH)

if (
!userConfig &&
fs.existsSync(configPath)
) {
if (!userConfig && fs.existsSync(configPath)) {
userConfig = await import(configPath)
}

if (userConfig === null) {
throw new Error(`next-i18next was unable to find a user config at ${configPath}`)
throw new Error(
`next-i18next was unable to find a user config at ${configPath}`
)
}

const config = createConfig({
Expand Down

0 comments on commit f538618

Please sign in to comment.