From 881ffe3fa9b3783a9beaa7c4480a7c19f9509a89 Mon Sep 17 00:00:00 2001 From: Aral Roca Gomez Date: Fri, 8 Oct 2021 14:25:55 +0200 Subject: [PATCH] Release 1.1.1 (#705) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(697): allow to disable colors (#698) * docs: add rubenmoya as a contributor for code (#699) * docs: update README.md [skip ci] * docs: update .all-contributorsrc [skip ci] Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> * Update package VERSION * Add pagesInDir config property + improve default (#701) * Add app and integrations folders for Blitz * Add pagesInPath configuration property * Fix (#704) * Update .npmrc Co-authored-by: Rubén Moya Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> --- .all-contributorsrc | 9 +++++++++ .npmrc | 2 +- README.md | 2 ++ package.json | 2 +- src/loadNamespaces.tsx | 8 +++++++- src/plugin/index.ts | 21 ++++++++++++++++----- 6 files changed, 36 insertions(+), 8 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 889e26c3..17dfc482 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -267,6 +267,15 @@ "contributions": [ "doc" ] + }, + { + "login": "rubenmoya", + "name": "Rubén Moya", + "avatar_url": "https://avatars.githubusercontent.com/u/905225?v=4", + "profile": "https://rubenmoya.dev", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 7, diff --git a/.npmrc b/.npmrc index b7704e88..5660f81a 100644 --- a/.npmrc +++ b/.npmrc @@ -1 +1 @@ -registry=http://registry.npmjs.org/ \ No newline at end of file +registry=https://registry.npmjs.org/ \ No newline at end of file diff --git a/README.md b/README.md index 423c5a69..1be36367 100644 --- a/README.md +++ b/README.md @@ -232,6 +232,7 @@ In the configuration file you can use both the configuration that we specified h | `interpolation` | Change the delimeter that is used for interpolation. | `{prefix: string; suffix: string}` | `{prefix: '{{', suffix: '}}'}` | `staticsHoc` | The HOCs we have in our API ([appWithI18n](#appwithi18n)), do not use [hoist-non-react-statics](https://github.com/mridgway/hoist-non-react-statics) in order not to include more kb than necessary _(static values different than getInitialProps in the pages are rarely used)_. If you have any conflict with statics, you can add hoist-non-react-statics (or any other alternative) here. [See an example](docs/hoist-non-react-statics.md). | `Function` | `null` | `extensionsRgx` | Change the regex used by the webpack loader to find Next.js pages. | `Regex` | `/\.(tsx\|ts\|js\|mjs\|jsx)$/` +| `pagesInDir` | If you run `next ./my-app` to change where your pages are, you can here define `my-app/pages` so that next-translate can guess where they are. | `String` | If you don't define it, by default the pages will be searched for in the classic places like `pages` and `src/pages`. ## 4. API @@ -873,6 +874,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
n4n5

📖 +
Rubén Moya

💻 diff --git a/package.json b/package.json index b89a921e..294fb048 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "next-translate", - "version": "1.1.0", + "version": "1.1.1-canary.3", "description": "Tiny and powerful i18n tools (Next plugin + API) to translate your Next.js pages.", "license": "MIT", "keywords": [ diff --git a/src/loadNamespaces.tsx b/src/loadNamespaces.tsx index 7dd14f6f..356e8a0e 100644 --- a/src/loadNamespaces.tsx +++ b/src/loadNamespaces.tsx @@ -2,6 +2,12 @@ import { LoaderConfig, LocaleLoader } from '.' import getConfig from './getConfig' import getPageNamespaces from './getPageNamespaces' +const colorEnabled = + process.env.NODE_DISABLE_COLORS == null && + process.env.NO_COLOR == null && + process.env.TERM !== 'dumb' && + process.env.FORCE_COLOR !== '0' + export default async function loadNamespaces( config: LoaderConfig = {} ): Promise<{ @@ -42,7 +48,7 @@ export default async function loadNamespaces( ).catch(() => {})) || [] if (conf.logBuild !== false && typeof window === 'undefined') { - const color = (c: string) => `\x1b[36m${c}\x1b[0m` + const color = (c: string) => (colorEnabled ? `\x1b[36m${c}\x1b[0m` : c) console.log( color('next-translate'), `- compiled page:`, diff --git a/src/plugin/index.ts b/src/plugin/index.ts index 4fa90931..7cfb04b5 100644 --- a/src/plugin/index.ts +++ b/src/plugin/index.ts @@ -10,21 +10,32 @@ export default function nextTranslate(nextConfig: any = {}) { path.relative(pkgDir(), process.env.NEXT_TRANSLATE_PATH || '.') ) - const arePagesInsideSrc = fs.existsSync(path.join(dir, 'src/pages')) - const i18n = nextConfig.i18n || {} - const { + let { locales, defaultLocale, loader = true, + pagesInDir, pages, logger, ...restI18n } = require(path.join(dir, 'i18n')) - // Check if exist a getInitialProps on _app.js let hasGetInitialPropsOnAppJs = false - const pagesPath = path.join(dir, arePagesInsideSrc ? '/src/pages' : '/pages') + + // https://github.com/blitz-js/blitz/blob/canary/nextjs/packages/next/build/utils.ts#L54-L59 + if (!pagesInDir) { + pagesInDir = 'pages' + if (fs.existsSync(path.join(dir, 'src/pages'))) { + pagesInDir = 'src/pages' + } else if (fs.existsSync(path.join(dir, 'app/pages'))) { + pagesInDir = 'app/pages' + } else if (fs.existsSync(path.join(dir, 'integrations/pages'))) { + pagesInDir = 'integrations/pages' + } + } + + const pagesPath = path.join(dir, pagesInDir) const app = fs .readdirSync(pagesPath) .find((page: string) => page.startsWith('_app.'))