Skip to content

Commit

Permalink
Merge branch 'main' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-bodnar committed Feb 20, 2023
2 parents 4aa80de + 34e14cd commit bfc2ed1
Show file tree
Hide file tree
Showing 19 changed files with 350 additions and 254 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ Lingui is an easy yet powerful internationalization framework for global project
message keys as well as auto-generated messages. Translations are stored either in
JSON or standard PO files, which are supported in almost all translation tools.

- **Lightweight and optimized** - Core library is only [1.9 kB gzipped][BundleCore],
React components are an additional [3.1 kBs gzipped][BundleReact]. That's less than Redux
- **Lightweight and optimized** - Core library is only [1.7 kB gzipped][BundleCore],
React components are an additional [1.6 kBs gzipped][BundleReact]. That's less than Redux
for a full-featured intl library.

- **Active community** - Join us on [Discord][Discord] to discuss the latest development.
Expand Down
9 changes: 7 additions & 2 deletions packages/cli/src/lingui-extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,14 @@ if (require.main === module) {

const changedPaths = new Set<string>()
let debounceTimer: NodeJS.Timer
let previousExtract = Promise.resolve(true)
const dispatchExtract = (filePath?: string[]) => {
// Skip debouncing if not enabled
if (!options.debounce) return extract(filePath)
// Skip debouncing if not enabled but still chain them so no racing issue
// on deleting the tmp folder.
if (!program.debounce) {
previousExtract = previousExtract.then(() => extract(filePath))
return previousExtract
}

filePath?.forEach((path) => changedPaths.add(path))

Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,16 @@ export type MissingMessageEvent = {
context?: string
}

type MissingHandler =
| string
| ((locale: string, id: string, context: string) => string)

type setupI18nProps = {
locale?: Locale
locales?: Locales
messages?: AllMessages
localeData?: AllLocaleData
missing?: string | ((message: string, id: string, context: string) => string)
missing?: MissingHandler
}

type Events = {
Expand All @@ -71,7 +75,7 @@ export class I18n extends EventEmitter<Events> {
private _locales: Locales
private _localeData: AllLocaleData
private _messages: AllMessages
private _missing: string | ((message, id, context) => string)
private _missing: MissingHandler

constructor(params: setupI18nProps) {
super()
Expand Down
2 changes: 1 addition & 1 deletion website/docs/guides/optimized-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { t, Trans } from '@lingui/macro'

class HeaderLink extends React.PureComponent {
render () {
return <a title={i18n._(t`Title`)}><Trans>Header</Trans></a>
return <a title={t`Title`}><Trans>Header</Trans></a>
}
}

Expand Down
2 changes: 1 addition & 1 deletion website/docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Integrate Lingui into your existing workflow. It supports message keys as well a

### Lightweight and optimized

Core library is only [3.4 kB gzipped](https://bundlephobia.com/result?p=@lingui/core), React components are additional [2.9 kB gzipped](https://bundlephobia.com/result?p=@lingui/react). That's less than Redux for a full-featured intl library.
Core library is only [1.7 kB gzipped](https://bundlephobia.com/result?p=@lingui/core), React components are additional [1.6 kB gzipped](https://bundlephobia.com/result?p=@lingui/react). That's less than Redux for a full-featured intl library.

### Active community

Expand Down
6 changes: 3 additions & 3 deletions website/docs/ref/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,13 @@ const i18n = setupI18n({ missing: "🚨" })
i18n._('missing translation') === "🚨"
```

This might be also a function which is called with active language and message ID:
This might be also a function which is called with active locale and message ID:

``` jsx
import { setupI18n } from "@lingui/core"

function missing(language, id) {
alert(`Translation in ${language} for ${id} is missing!`)
function missing(locale, id) {
alert(`Translation in ${locale} for ${id} is missing!`)
return id
}

Expand Down
10 changes: 7 additions & 3 deletions website/docs/ref/macro.md
Original file line number Diff line number Diff line change
Expand Up @@ -792,18 +792,22 @@ import { SelectOrdinal } from "@lingui/macro"
> MessageFormat: `{arg, select, ...forms}`
:::note
The select cases except `other` should be prefixed with underscore: `_male` or `_female`.
:::
Props of `Select` macro are transformed into [`select`](/docs/ref/message-format.md) format:
``` jsx
import { Select } from "@lingui/macro"
// gender == "female" -> Her book
// gender == "male" -> His book
// gender == "unspecified" -> Their book
// gender == "non-binary" -> Their book
<Select
value={gender}
male="His book"
female="Her book"
_male="His book"
_female="Her book"
other="Their book"
/>
```
28 changes: 16 additions & 12 deletions website/docs/ref/swc-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,22 @@ Add the following configuration to your [`.swcrc`](https://swc.rs/docs/configura
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"experimental": {
"plugins": ["@lingui/swc-plugin", {

// Optional
// Unlike the JS version this option must be passed as object only.
// Docs https://lingui.js.org/ref/conf.html#std-config-runtimeConfigModule
// "runtimeModules": {
// "i18n": ["@lingui/core", "i18n"],
// "trans": ["@lingui/react", "Trans"]
// }
}]
}
}
"plugins": [
[
"@lingui/swc-plugin",
{
// Optional
// Unlike the JS version this option must be passed as object only.
// Docs https://lingui.dev/ref/conf#runtimeconfigmodule
// "runtimeModules": {
// "i18n": ["@lingui/core", "i18n"],
// "trans": ["@lingui/react", "Trans"]
// }
},
],
],
},
},
}
```

Expand Down
14 changes: 8 additions & 6 deletions website/docs/tools/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@ Instead of manually sending and receiving many emails and fixing the inconsisten

## Configure your project

To synchronize your current application with an online tool, you just have to add these lines at the end of your `.linguirc` configuration file:
To synchronize your current application with an online tool, you just have to add these lines at the end of your `lingui.config.js` configuration file:

```js title=".linguirc"
{
```js title="lingui.config.js"
/** @type {import('@lingui/conf').LinguiConfig} */
module.exports = {
[...]
"service": {
"name": "ToolName",
"apiKey": "abcdefghijklmnopqrstuvwxyz012345"
service: {
name: "ToolName",
apiKey: "abcdefghijklmnopqrstuvwxyz012345"
}
}

```

The synchronization will then be part of the [`extract`](/docs/ref/cli.md#extract) command.
Expand Down
17 changes: 9 additions & 8 deletions website/docs/tutorials/react.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,15 @@ No locales defined!
Add 'locales' to your configuration. See https://lingui.dev/ref/conf#locales
```

We need here to fix the configuration. Create a `.linguirc` file:

```json title=".linguirc"
{
"locales": ["cs", "en"],
"catalogs": [{
"path": "src/locales/{locale}/messages",
"include": ["src"]
We need here to fix the configuration. Create a `lingui.config.js` file:

```js title="lingui.config.js"
/** @type {import('@lingui/conf').LinguiConfig} */
module.exports = {
locales: ["cs", "en"],
catalogs: [{
path: "src/locales/{locale}/messages",
include: ["src"]
}]
}
```
Expand Down
21 changes: 11 additions & 10 deletions website/docs/tutorials/setup-cra.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@
npm install --save @lingui/macro @lingui/react
```

3. Create `.linguirc` file with LinguiJS configuration in root of your project (next to `package.json`):

``` json title=".linguirc"
{
"locales": ["en", "cs", "fr"],
"sourceLocale": "en",
"catalogs": [{
"path": "src/locales/{locale}/messages",
"include": ["src"]
3. Create `lingui.config.js` file with LinguiJS configuration in root of your project (next to `package.json`):

```js title="lingui.config.js"
/** @type {import('@lingui/conf').LinguiConfig} */
module.exports = {
locales: ["en", "cs", "fr"],
sourceLocale: "en",
catalogs: [{
path: "src/locales/{locale}/messages",
include: ["src"]
}],
"format": "po"
format: "po"
}
```

Expand Down
19 changes: 10 additions & 9 deletions website/docs/tutorials/setup-react.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@ This setup guide is for any project which uses React.
If you use any preset, check first if it contains `macros` plugin. These presets already includes `macros` plugin: `react-scripts`
:::
3. Create `.linguirc` file with LinguiJS configuration in root of your project (next to `package.json`). Replace `src` with a directory name where you have source files:
```json title=".linguirc"
{
"locales": ["en", "cs", "fr"],
"catalogs": [{
"path": "src/locales/{locale}/messages",
"include": ["src"]
3. Create `lingui.config.js` file with LinguiJS configuration in root of your project (next to `package.json`). Replace `src` with a directory name where you have source files:
```js title="lingui.config.js"
/** @type {import('@lingui/conf').LinguiConfig} */
module.exports = {
locales: ["en", "cs", "fr"],
catalogs: [{
path: "src/locales/{locale}/messages",
include: ["src"]
}],
"format": "po"
format: "po"
}
```
Expand Down
12 changes: 6 additions & 6 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"fixFormat": "prettier --write ."
},
"dependencies": {
"@docusaurus/core": "2.2.0",
"@docusaurus/preset-classic": "2.2.0",
"@docusaurus/remark-plugin-npm2yarn": "^2.2.0",
"@docusaurus/core": "2.3.1",
"@docusaurus/preset-classic": "2.3.1",
"@docusaurus/remark-plugin-npm2yarn": "^2.3.1",
"@mdx-js/react": "1.6.22",
"clsx": "1.2.1",
"docusaurus-plugin-sass": "^0.2.3",
Expand All @@ -31,9 +31,9 @@
"not op_mini all"
],
"devDependencies": {
"@docusaurus/eslint-plugin": "2.2.0",
"@docusaurus/module-type-aliases": "2.2.0",
"@docusaurus/utils": "2.2.0",
"@docusaurus/eslint-plugin": "2.3.1",
"@docusaurus/module-type-aliases": "2.3.1",
"@docusaurus/utils": "2.3.1",
"@tsconfig/docusaurus": "1.0.6",
"@types/react": "17.0.0",
"@types/react-helmet": "6.1.6",
Expand Down
8 changes: 8 additions & 0 deletions website/src/components/Code.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.code {
margin-top: 80px;
margin-bottom: 40px;
}

.linkExamples {
text-align: center;
}
41 changes: 41 additions & 0 deletions website/src/components/Code.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';
import clsx from 'clsx';
import { useBaseUrlUtils } from '@docusaurus/useBaseUrl';
import CodeBlock from '@theme/CodeBlock';
import Button from './Button';

import styles from './Code.module.scss';

const Code = (): React.ReactElement => {
const { withBaseUrl } = useBaseUrlUtils();

const codeSample = `
import { Trans } from "@lingui/macro"
function App() {
return (
<Trans id="msg.docs">
Read the <a href="https://lingui.dev">documentation</a>
for more info.
</Trans>
)
}
`;

return (
<section className={clsx(styles.code, 'col col--6 col--offset-3')}>
<div className="container">
<h2 className={'text--center margin-bottom--lg'}>Integrating Lingui into Your Project is Easy!</h2>
<CodeBlock className="language-jsx">{codeSample.trim()}</CodeBlock>
</div>

<div className={styles.linkExamples}>
<Button href={withBaseUrl('/tutorials/react')} isOutline={true}>
More Examples
</Button>
</div>
</section>
);
};

export default Code;
1 change: 0 additions & 1 deletion website/src/components/Features.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
}

.linkFeatures {
margin-top: 2rem;
text-align: center;
}

Expand Down
6 changes: 6 additions & 0 deletions website/src/components/Header.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
font-weight: 700;
}

@media only screen and (max-width: 600px) {
.heroTitle {
font-size: 2rem;
}
}

.heroBannerLogo {
max-width: 170px;
max-height: 170px;
Expand Down
2 changes: 2 additions & 0 deletions website/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import Features from '../components/Features';
import Header from '../components/Header';
import Users from '../components/Users';
import Code from '../components/Code';

function Home() {
const { siteConfig } = useDocusaurusContext();
Expand All @@ -13,6 +14,7 @@ function Home() {
<Header />
<main className={'main-page-content'}>
<Features />
<Code />
<Users />
</main>
</Layout>
Expand Down
Loading

0 comments on commit bfc2ed1

Please sign in to comment.