Skip to content

Commit

Permalink
Add initial project files (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrpospiech authored Oct 9, 2023
1 parent 15dfe8d commit 0db8a9e
Show file tree
Hide file tree
Showing 19 changed files with 10,605 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": ["vazco/typescript"],
"parser": "@typescript-eslint/parser",
"ignorePatterns": ["dist/*"],
"rules": {
"react-hooks/exhaustive-deps": 1,
"eslint-comments/require-description": 0
}
}
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @piotrpospiech
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
dist/
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"arrowParens": "avoid",
"bracketSpacing": true,
"printWidth": 80,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all"
}
7 changes: 7 additions & 0 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": ["stylelint-config-standard"],
"rules": {
"selector-class-pattern": "^i18n-table--([a-z][a-z0-9]*)(-[a-z0-9]+)*$",
"custom-property-pattern": "^i18n-table--([a-z][a-z0-9]*)(-[a-z0-9]+)*$"
}
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2023 Vazco

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
89 changes: 88 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,89 @@
# i18n-table
A React component that helps organize and manage translations

## Installation

```
npm install i18n-table
```

## Get started

1. Import `TranslationManager` and styles

```js
import TranslationManager from 'i18n-table';
import 'i18n-table/dist/index.css';
```

2. Prepare translations

```js
const translations = {
en: {
colors: {
red: 'Red',
blue: 'Blue',
green: 'Green',
},
},
es: {
colors: {
red: 'Rojo',
green: 'Verde',
},
},
};
```

`translations` object should have **locales** as keys and **objects or nested objects** as values.

3. Prepare locales with full and local names.

> [!IMPORTANT]
> The `locale` property have to match with locale used in the first step.
```js
const locales = [
{ locale: 'en', fullName: 'English', localName: 'English' },
{ locale: 'es', fullName: 'Spanish', localName: 'Español' },
];
```

4. Render `TranslationManager` on your page

```js
export const App = () => (
<TranslationManager
translations={translations}
locales={locales}
onSave={translations => {
/* Handle saving translations - structure is the same as in the step 2. */
}}
/>
);
```

5. If you want to write **your own styles**, copy `/src/lib/styles.css` file to your project, modify it and import it instead of `i18n-table/dist/index.css`

6. You can also customize header translations.

```js
const componentTranslations = {
save: t('save'),
search: t('search'),
select: t('select'),
translationKey: t('translationKey'),
};

export const App = () => (
<TranslationManager
// ...
componentTranslations={componentTranslations}
onLocaleChange={locale => i18n.setLocale(locale)}
/>
);
```

## License

**Like every package maintained by [Vazco](https://vazco.eu/), i18n-table package is [MIT licensed](https://github.com/vazco/i18n-table/blob/master/LICENSE).**
Loading

0 comments on commit 0db8a9e

Please sign in to comment.