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

RFC-002 - Catalogs #326

Merged
merged 46 commits into from
May 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
f2977ad
feat: migrate lingui config
tricoder42 Sep 12, 2018
e786923
refactor: remove add-locale command
tricoder42 Sep 12, 2018
bef8c9d
refactor: add flow types to conf package
tricoder42 Oct 5, 2018
38be070
style: update flow-typed definitions
tricoder42 Oct 5, 2018
c7fd923
test: rename test to match package name
tricoder42 Oct 5, 2018
cf79777
refactor: remove add-locale catalog method
tricoder42 Oct 5, 2018
8fc03f7
wip: parse config.catalogs and return catalog isntances
tricoder42 Oct 6, 2018
d613ffa
wip: collect messages from files
tricoder42 Oct 7, 2018
00f4e12
wip
tricoder42 Oct 10, 2018
df1e65e
wip
tricoder42 Oct 12, 2018
19dc2c2
feat: validate locales and warn about missing this config
tricoder42 Oct 12, 2018
f45bfb9
wip
tricoder42 Oct 13, 2018
c8d84c2
wip: reafactor catalogs configuration
tricoder42 Oct 13, 2018
c28e5ba
wip: fix extract tests
tricoder42 Oct 13, 2018
d24c3e5
wip: ignore fixtures in babel
tricoder42 Oct 13, 2018
3b5385e
wip: migrate catalogs to use new config
tricoder42 Oct 13, 2018
bf5705c
chore: don't write bundle stats by defualt
tricoder42 Oct 13, 2018
e5db35e
wip: optionally skip config validation
tricoder42 Oct 13, 2018
9efcb4a
wip: pass project type to extractors
tricoder42 Oct 13, 2018
b6c09ca
wip: use new catalogs config in create-react-app example
tricoder42 Oct 13, 2018
2dd97dc
wip: get matching catalog for catalog filename
tricoder42 Oct 13, 2018
be5567e
fix default root dir in tests
tricoder42 Oct 13, 2018
746ef8b
fix babel ignore patterns
tricoder42 Oct 13, 2018
316998c
fix linter errors
tricoder42 Oct 13, 2018
3e552ee
fix babel ignore patterns
tricoder42 Oct 13, 2018
605411b
refactor lingui-compile to new catalog config
tricoder42 Oct 13, 2018
d4bb6db
rever babel config, add release:integration command
tricoder42 Oct 13, 2018
fc140a5
fix linter errors
tricoder42 Oct 13, 2018
479fadb
make binarie executable in examples
tricoder42 Oct 13, 2018
db10cc9
fix babel ignore patterns
tricoder42 Oct 13, 2018
0a51e79
update lock files in examples
tricoder42 Oct 13, 2018
cb00a15
fix linter errors
tricoder42 Oct 13, 2018
332b397
update packages
tricoder42 Oct 13, 2018
f0c0d2c
fix snapshot
tricoder42 Oct 13, 2018
a70f357
enable ordering and filtering
tricoder42 Oct 14, 2018
882de1d
update catalogs in example
tricoder42 Oct 14, 2018
a7c2b90
wip
tricoder42 Oct 29, 2018
5227de3
Merge branch 'next' into catalogs
tricoder42 May 20, 2019
a7457a8
chore: remove babel-eslint parser
tricoder42 May 20, 2019
e45eb8f
style: fix typings in conf package
tricoder42 May 23, 2019
87f0cd9
Merge branch 'next' into rfc/002-catalogs
tricoder42 May 23, 2019
112ffb7
style: fix typings in react package
tricoder42 May 23, 2019
897ce37
style: fix typings in macro package
tricoder42 May 23, 2019
b4d2c74
style: fix typings in cli package
tricoder42 May 23, 2019
44e63c6
style(conf): fix catalog format
tricoder42 May 23, 2019
a05d40c
style: fix remainging types
tricoder42 May 23, 2019
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
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"env": {
"jest/globals": true
},
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
Expand Down
975 changes: 898 additions & 77 deletions examples/babel-6-react-with-macros/yarn.lock

Large diffs are not rendered by default.

714 changes: 714 additions & 0 deletions examples/babel-6-react/yarn.lock

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion examples/create-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
"babel-core": "^7.0.0-bridge.0"
},
"lingui": {
"localeDir": "src/locales",
"catalogs": [{
"path": "src/locales/{locale}",
"include": ["src"]
}],
"locales": ["en", "cs"],
"format": "po",
"sourceLocale": "en"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/create-react-app/src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const locales = {
}

function loadCatalog(locale) {
return import(`@lingui/loader!./locales/${locale}/messages.po`)
return import(`@lingui/loader!./locales/${locale}.po`)
}

export const i18n = setupI18n()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
msgid ""
msgstr ""
"POT-Creation-Date: 2018-10-05 11:01+0200\n"
"POT-Creation-Date: 2018-10-13 13:51+0200\n"
"Mime-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
msgid ""
msgstr ""
"POT-Creation-Date: 2018-10-05 11:01+0200\n"
"POT-Creation-Date: 2018-10-13 13:51+0200\n"
"Mime-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand All @@ -15,12 +15,12 @@ msgstr ""

#: src/App.js:24
msgid "Edit <0>src/App.js</0> and save to reload."
msgstr ""
msgstr "Edit <0>src/App.js</0> and save to reload."

#: src/App.js:35
msgid "Learn React"
msgstr ""
msgstr "Learn React"

#: src/App.js:19
msgid "logo"
msgstr ""
msgstr "logo"
468 changes: 468 additions & 0 deletions examples/js/yarn.lock

Large diffs are not rendered by default.

3,252 changes: 3,238 additions & 14 deletions examples/react/yarn.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"lint:eslint": "eslint packages/",
"lint": "yarn lint:eslint; yarn lint:types",
"release": "node ./scripts/release.js",
"release:integration": "node ./scripts/integration.js",
"release:build": "node ./scripts/build/",
"release:test": "node ./scripts/test.js"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-extract-messages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"node": ">=8.0.0"
},
"dependencies": {
"@babel/generator": "^7.0.0",
"@babel/generator": "^7.1.3",
"@lingui/conf": "0.0.0-managed-by-release-script"
}
}
21 changes: 15 additions & 6 deletions packages/babel-plugin-extract-messages/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import mkdirp from "mkdirp"
import generate from "@babel/generator"
import { getConfig } from "@lingui/conf"

const CONFIG = Symbol("I18nConfig")

// Map of messages
const MESSAGES = Symbol("I18nMessages")

Expand Down Expand Up @@ -40,9 +42,6 @@ function addMessage(
export default function({ types: t }) {
let localTransComponentName

const opts = getConfig()
const optsBaseDir = opts.rootDir

function isTransComponent(node) {
return (
t.isJSXElement(node) &&
Expand All @@ -60,8 +59,9 @@ export default function({ types: t }) {
function collectMessage(path, file, props) {
const messages = file.get(MESSAGES)

const rootDir = file.get(CONFIG).rootDir
const filename = fsPath
.relative(optsBaseDir, file.opts.filename)
.relative(rootDir, file.opts.filename)
.replace(/\\/g, "/")
const line = path.node.loc ? path.node.loc.start.line : null
props.origin = [[filename, line]]
Expand Down Expand Up @@ -195,6 +195,13 @@ export default function({ types: t }) {
pre(file) {
localTransComponentName = null

// Skip validation because config is loaded for each file.
// Config was already validated in CLI.
file.set(
CONFIG,
getConfig({ cwd: file.opts.filename, skipValidation: true })
)

// Ignore else path for now. Collision is possible if other plugin is
// using the same Symbol('I18nMessages').
// istanbul ignore else
Expand All @@ -210,9 +217,11 @@ export default function({ types: t }) {
* e.g: if file is src/components/App.js (relative to package.json), then
* catalog will be in locale/_build/src/components/App.json
*/
const localeDir = this.opts.localeDir || opts.localeDir
const config = file.get(CONFIG)
const localeDir = this.opts.localeDir || config.localeDir
const { filename } = file.opts
const baseDir = fsPath.dirname(fsPath.relative(optsBaseDir, filename))
const rootDir = config.rootDir
const baseDir = fsPath.dirname(fsPath.relative(rootDir, filename))
const targetDir = fsPath.join(localeDir, "_build", baseDir)

const messages = file.get(MESSAGES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Object {
{count, plural, one {# book} other {# books}}: Object {
origin: Array [
Array [
packages/babel-plugin-extract-messages/test/fixtures/jsx-without-trans.js,
jsx-without-trans.js,
3,
],
],
Expand All @@ -19,7 +19,7 @@ Object {
comment: description,
origin: Array [
Array [
packages/babel-plugin-extract-messages/test/fixtures/js-with-macros.js,
js-with-macros.js,
7,
],
],
Expand All @@ -28,27 +28,27 @@ Object {
message: Message with id,
origin: Array [
Array [
packages/babel-plugin-extract-messages/test/fixtures/js-with-macros.js,
js-with-macros.js,
12,
],
],
},
Message: Object {
origin: Array [
Array [
packages/babel-plugin-extract-messages/test/fixtures/js-with-macros.js,
js-with-macros.js,
3,
],
Array [
packages/babel-plugin-extract-messages/test/fixtures/js-with-macros.js,
js-with-macros.js,
5,
],
],
},
Values {param}: Object {
origin: Array [
Array [
packages/babel-plugin-extract-messages/test/fixtures/js-with-macros.js,
js-with-macros.js,
17,
],
],
Expand All @@ -57,15 +57,15 @@ Object {
comment: Descriptor with comment,
origin: Array [
Array [
packages/babel-plugin-extract-messages/test/fixtures/js-with-macros.js,
js-with-macros.js,
21,
],
],
},
defineMessages - string: Object {
origin: Array [
Array [
packages/babel-plugin-extract-messages/test/fixtures/js-with-macros.js,
js-with-macros.js,
20,
],
],
Expand All @@ -79,7 +79,7 @@ Object {
comment: description,
origin: Array [
Array [
packages/babel-plugin-extract-messages/test/fixtures/js-without-macros.js,
js-without-macros.js,
9,
],
],
Expand All @@ -88,27 +88,27 @@ Object {
message: Message with id,
origin: Array [
Array [
packages/babel-plugin-extract-messages/test/fixtures/js-without-macros.js,
js-without-macros.js,
14,
],
],
},
Message: Object {
origin: Array [
Array [
packages/babel-plugin-extract-messages/test/fixtures/js-without-macros.js,
js-without-macros.js,
1,
],
Array [
packages/babel-plugin-extract-messages/test/fixtures/js-without-macros.js,
js-without-macros.js,
5,
],
],
},
Values {param}: Object {
origin: Array [
Array [
packages/babel-plugin-extract-messages/test/fixtures/js-without-macros.js,
js-without-macros.js,
19,
],
],
Expand All @@ -117,15 +117,15 @@ Object {
comment: Descriptor with comment,
origin: Array [
Array [
packages/babel-plugin-extract-messages/test/fixtures/js-without-macros.js,
js-without-macros.js,
28,
],
],
},
defineMessages - string: Object {
origin: Array [
Array [
packages/babel-plugin-extract-messages/test/fixtures/js-without-macros.js,
js-without-macros.js,
27,
],
],
Expand All @@ -138,23 +138,23 @@ Object {
Hi, my name is {name}: Object {
origin: Array [
Array [
packages/babel-plugin-extract-messages/test/fixtures/jsx-with-macros.js,
jsx-with-macros.js,
3,
],
],
},
Title: Object {
origin: Array [
Array [
packages/babel-plugin-extract-messages/test/fixtures/jsx-with-macros.js,
jsx-with-macros.js,
4,
],
],
},
{count, plural, one {# book} other {# books}}: Object {
origin: Array [
Array [
packages/babel-plugin-extract-messages/test/fixtures/jsx-with-macros.js,
jsx-with-macros.js,
6,
],
],
Expand All @@ -167,7 +167,7 @@ Object {
Hi, my name is <0>{name}</0>: Object {
origin: Array [
Array [
packages/babel-plugin-extract-messages/test/fixtures/jsx-without-macros.js,
jsx-without-macros.js,
9,
],
],
Expand All @@ -176,11 +176,11 @@ Object {
message: Hello World,
origin: Array [
Array [
packages/babel-plugin-extract-messages/test/fixtures/jsx-without-macros.js,
jsx-without-macros.js,
7,
],
Array [
packages/babel-plugin-extract-messages/test/fixtures/jsx-without-macros.js,
jsx-without-macros.js,
8,
],
],
Expand All @@ -189,7 +189,7 @@ Object {
comment: Description,
origin: Array [
Array [
packages/babel-plugin-extract-messages/test/fixtures/jsx-without-macros.js,
jsx-without-macros.js,
6,
],
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"locales": ["en", "cs"]
}
17 changes: 4 additions & 13 deletions packages/babel-plugin-extract-messages/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@ import plugin from "@lingui/babel-plugin-extract-messages"

const LOCALE_DIR = "./locale"

// CWD is root directory of repository, so origin of all messages is going to
// relative to root
const buildDir = path.join(
LOCALE_DIR,
"_build",
"packages",
"babel-plugin-extract-messages",
"test",
"fixtures"
)
const buildDir = path.join(LOCALE_DIR, "_build")

const rmdir = dir => {
if (!fs.existsSync(dir)) return
Expand All @@ -39,7 +30,7 @@ const rmdir = dir => {
}

function testCase(testName, assertion) {
const transform = (filename, jsx = true) => () => {
const transform = filename => () => {
process.env.LINGUI_EXTRACT = "1"
try {
return transformFileSync(path.join(__dirname, "fixtures", filename), {
Expand All @@ -65,9 +56,9 @@ function testCase(testName, assertion) {
} else {
it(testName, () => {
// first run should create all required folders and write messages
expect(transform(assertion, false)).not.toThrow()
expect(transform(assertion)).not.toThrow()
// another runs should just write messages
expect(transform(assertion, false)).not.toThrow()
expect(transform(assertion)).not.toThrow()

const messages = JSON.parse(
fs.readFileSync(path.join(buildDir, `${assertion}.json`)).toString()
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@
"*.js.flow"
],
"dependencies": {
"@babel/core": "^7.1.0",
"@babel/generator": "^7.0.0",
"@babel/parser": "^7.1.0",
"@babel/generator": "^7.1.3",
"@babel/parser": "^7.1.3",
"@babel/plugin-syntax-jsx": "^7.0.0",
"@babel/runtime": "^7.0.0",
"@babel/types": "^7.0.0",
"@babel/types": "^7.1.3",
"@lingui/babel-plugin-extract-messages": "0.0.0-managed-by-release-script",
"@lingui/conf": "0.0.0-managed-by-release-script",
"babel-plugin-macros": "^2.4.1",
Expand All @@ -53,6 +52,7 @@
"inquirer": "^6.3.1",
"make-plural": "^4.1.1",
"messageformat-parser": "^2.0.0",
"minimatch": "^3.0.4",
"mkdirp": "^0.5.1",
"ora": "^3.4.0",
"pofile": "^1.0.11",
Expand All @@ -64,6 +64,6 @@
"mockdate": "^2.0.2"
},
"peerDependencies": {
"babel-core": "6.x || ^7.0.0-bridge.0"
"babel-core": "^6.0.0 | ^7.0.0-bridge.0"
}
}
Loading