Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
fakundo committed Apr 20, 2021
1 parent ab9cf0a commit 7f74618
Show file tree
Hide file tree
Showing 30 changed files with 348 additions and 163 deletions.
6 changes: 6 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
]
}
14 changes: 8 additions & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{
"extends": "airbnb",
"parser": "babel-eslint",
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": 2017,
"ecmaFeatures": {
"legacyDecorators": true
}
"requireConfigFile": false,
"ecmaVersion": 2017
},
"globals": {
"window": true,
Expand All @@ -18,7 +16,11 @@
"react/jsx-props-no-spreading": 0,
"react/jsx-curly-newline": 0,
"object-curly-newline": 0,
"semi": ["error", "never"],
"semi": [
"error",
"never"
],
"react/prefer-stateless-function": 0,
"react/prop-types": 0,
"no-plusplus": 0
}
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/build-deploy-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Build Docs
on:
push:
branches:
- master
jobs:
build-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/[email protected]

- name: Install and Build 🔧
run: |
yarn
yarn run docs
- name: Deploy 🚀
uses: JamesIves/[email protected]
with:
branch: gh-pages
folder: docs
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
lib
docs

# Node specific #
#################
Expand Down
19 changes: 13 additions & 6 deletions examples/locales/ru.po
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,32 @@ msgstr ""
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-SearchPath-0: .\n"

#: ../../examples/src/DecoratedClassComponent.js:12
#: ../../examples/src/DecoratedFunctionalComponent.js:8
#: ../../examples/src/HookedComponent.js:10
#: ../../examples/src/DecoratedClassComponent.js:10
#: ../../examples/src/DecoratedFunctionalComponent.js:7
#: ../../examples/src/HookedComponent.js:9
msgid "%s apple"
msgid_plural "%s apples"
msgstr[0] "%s яблоко"
msgstr[1] "%s яблока"
msgstr[2] "%s яблок"

#: ../../examples/src/DecoratedFunctionalComponent.js:8
msgid "%s table"
msgid_plural "%s tables"
msgstr[0] "%s стол"
msgstr[1] "%s стола"
msgstr[2] "%s столов"

#: ../../examples/src/HookedComponent.js:8
msgid "Hello, world!"
msgstr "Привет, мир!"

#: ../../examples/src/DecoratedClassComponent.js:10
#: ../../examples/src/DecoratedClassComponent.js:9
#: ../../examples/src/DecoratedFunctionalComponent.js:6
msgid "My name is %s"
msgstr "Мое имя %s"

#: ../../examples/src/HookedComponent.js:12
#: ../../examples/src/HookedComponent.js:10
msgctxt "Context"
msgid "Text with context"
msgstr "Текст с контекстом"
msgstr "Текст с контекстом"
36 changes: 23 additions & 13 deletions examples/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,32 @@ import DecoratedClassComponent from './DecoratedClassComponent'
import locales from '../locales'

export default () => {
const [selectedLocale, setSelectedLocale] = useState('en')
const toggleLocale = useCallback(() => setSelectedLocale((selected) => (selected === 'en' ? 'ru' : 'en')), [])
const [locale, setLocale] = useState('en')

const toggleLocale = useCallback(() => {
setLocale((prev) => (prev === 'en' ? 'ru' : 'en'))
}, [])

return (
<>
<button onClick={toggleLocale} type="button">toggle locale</button>
<button
type="button"
onClick={toggleLocale}
>
Toggle locale
</button>
<hr />
<LocalizedProvider locales={locales} selected={selectedLocale}>
{ ({ localeReady }) => (localeReady
? (
<>
<HookedComponent />
<DecoratedFunctionalComponent />
<DecoratedClassComponent />
</>
)
: 'loading locale'
<LocalizedProvider locales={locales} selected={locale}>
{({ localeReady }) => (
localeReady
? (
<>
<HookedComponent />
<DecoratedFunctionalComponent />
<DecoratedClassComponent />
</>
)
: 'loading locale'
)}
</LocalizedProvider>
</>
Expand Down
16 changes: 7 additions & 9 deletions examples/src/DecoratedClassComponent.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import React, { Component } from 'react'
import { withLocales } from 'react-localized'

@withLocales()
export default class DecoratedClassComponent extends Component {
class DecoratedClassComponent extends Component {
render() {
const { gettext, ngettext, formats, formatDate } = this.props
const { gettext, formats, formatDate } = this.props
return (
<>
{gettext('My name is %s', 'Anna')}
<br />
{ngettext('%s apple', '%s apples', 10, 10)}
<br />
{formatDate(new Date(), formats.date)}
<br />
<p>{gettext('My name is %s', 'Anna')}</p>
<p>{gettext('My name is %s', 'John')}</p>
<p>{formatDate(new Date(), formats.date)}</p>
</>
)
}
}

export default withLocales()(DecoratedClassComponent)
16 changes: 8 additions & 8 deletions examples/src/DecoratedFunctionalComponent.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react'
import { withLocales } from 'react-localized'

export default withLocales()(({ gettext, ngettext }) => (
const DecoratedFunctionalComponent = ({ ngettext }) => (
<>
{gettext('My name is %s', 'John')}
<br />
{ngettext('%s apple', '%s apples', 2, 2)}
<br />
{ngettext('%s table', '%s tables', 10, 10)}
<br />
<p>{ngettext('%s apple', '%s apples', 1, 1)}</p>
<p>{ngettext('%s apple', '%s apples', 2, 2)}</p>
<p>{ngettext('%s apple', '%s apples', 10, 10)}</p>
<p>{ngettext('%s table', '%s tables', 5, 5)}</p>
</>
))
)

export default withLocales()(DecoratedFunctionalComponent)
10 changes: 3 additions & 7 deletions examples/src/HookedComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ import React from 'react'
import { useLocales } from 'react-localized'

export default () => {
const { gettext, ngettext, pgettext } = useLocales()
const { gettext, pgettext } = useLocales()
return (
<>
{gettext('Hello, world!')}
<br />
{ngettext('%s apple', '%s apples', 1, 1)}
<br />
{pgettext('Context', 'Text with context')}
<br />
<p>{gettext('Hello, world!')}</p>
<p>{pgettext('Context', 'Text with context')}</p>
</>
)
}
51 changes: 26 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,38 @@
"name": "root",
"private": true,
"scripts": {
"dev:extract": "lerna run build && lerna run dev:extract",
"dev": "lerna run build && lerna run dev:react",
"docs": "lerna run build && lerna run docs:react",
"preversion": "lerna run lint",
"dev": "lerna run dev:react",
"publish:patch": "lerna version patch --force-publish --no-changelog && lerna publish from-package",
"publish:minor": "lerna version minor --force-publish --no-changelog && lerna publish from-package",
"publish:major": "lerna version major --force-publish --no-changelog && lerna publish from-package"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.4",
"@babel/plugin-proposal-decorators": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.8.3",
"@babel/preset-env": "^7.8.4",
"@babel/preset-react": "^7.8.3",
"babel-eslint": "^10.0.3",
"babel-loader": "^8.0.6",
"date-fns": "^2.9.0",
"eslint": "^6.8.0",
"eslint-config-airbnb": "^18.0.1",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.18.3",
"eslint-plugin-react-hooks": "^1.7.0",
"html-webpack-plugin": "^3.2.0",
"lerna": "^3.20.2",
"microbundle": "^0.11.0",
"preact": "^10.3.2",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"@babel/cli": "^7.13.16",
"@babel/core": "^7.13.16",
"@babel/eslint-parser": "^7.13.14",
"@babel/plugin-transform-runtime": "^7.13.15",
"@babel/preset-env": "^7.13.15",
"@babel/preset-react": "^7.13.13",
"babel-loader": "^8.2.2",
"date-fns": "^2.21.1",
"eslint": "^7.24.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.23.2",
"eslint-plugin-react-hooks": "^4.2.0",
"html-webpack-plugin": "^5.3.1",
"lerna": "^4.0.0",
"microbundle": "^0.13.0",
"preact": "^10.5.13",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"rimraf": "^3.0.2",
"webpack": "^4.41.6",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3"
"webpack": "^5.34.0",
"webpack-cli": "^4.6.0",
"webpack-dev-server": "^3.11.2"
}
}
2 changes: 1 addition & 1 deletion packages/preact-localized/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2020 Roman Samoylov
Copyright (c) 2021 Roman Samoylov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Loading

0 comments on commit 7f74618

Please sign in to comment.