mirror of
https://github.com/IT4Change/boilerplate-frontend.git
synced 2025-12-13 07:35:53 +00:00
lint-locales
This commit is contained in:
parent
bdec96c9ec
commit
68163e5a98
@ -13,8 +13,7 @@
|
||||
"plugin:promise/recommended",
|
||||
"plugin:security/recommended",
|
||||
"plugin:vue/vue3-recommended",
|
||||
"plugin:storybook/recommended",
|
||||
"plugin:prettier/recommended"
|
||||
"plugin:storybook/recommended"
|
||||
],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": "latest",
|
||||
@ -23,7 +22,6 @@
|
||||
},
|
||||
"plugins": [
|
||||
"@typescript-eslint",
|
||||
"prettier",
|
||||
"import",
|
||||
"promise",
|
||||
"security",
|
||||
@ -40,7 +38,6 @@
|
||||
"no-console": "error",
|
||||
"no-debugger": "error",
|
||||
"camelcase": "error",
|
||||
"prettier/prettier": "error",
|
||||
"indent": ["error", 2],
|
||||
"linebreak-style": ["error", "unix"],
|
||||
"semi": ["error", "never"],
|
||||
@ -120,6 +117,14 @@
|
||||
"promise/no-multiple-resolved": "error"
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["!*.json"],
|
||||
"plugins": ["prettier"],
|
||||
"extends": ["plugin:prettier/recommended"],
|
||||
"rules": {
|
||||
"prettier/prettier": "error"
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": ["*.json"],
|
||||
"plugins": ["json"],
|
||||
@ -131,7 +136,7 @@
|
||||
"extends": ["plugin:vuetify/recommended"]
|
||||
},
|
||||
{
|
||||
"files": ["**/*.test.[tj]s"],
|
||||
"files": ["*.[test,spec].[tj]s"],
|
||||
"plugins": ["vitest"],
|
||||
"extends": ["plugin:vitest/all"]
|
||||
},
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
[![nodejs][badge-nodejs-img]][badge-nodejs-href]
|
||||
[![npm][badge-npm-img]][badge-npm-href]
|
||||
[![docker][badge-docker-img]][badge-docker-href]
|
||||
[![jq][badge-jq-img]][badge-jq-href]
|
||||
[![vue][badge-vue-img]][badge-vue-href]
|
||||
[![vike][badge-vike-img]][badge-vike-href]
|
||||
[![vuetify][badge-vuetify-img]][badge-vuetify-href]
|
||||
@ -18,7 +19,7 @@ The IT4C Boilerplate for frontends
|
||||
|
||||
## Requirements & Technology
|
||||
|
||||
To be able to build this project you need `nodejs`, `npm` and optional `docker`.
|
||||
To be able to build this project you need `nodejs`, `npm` and optional `docker` and `jq`.
|
||||
|
||||
The project uses `vite` as builder, `vike` to do the SSR. The design framework is `vuetify` which requires the frontend framework `vue3`. For localization `vue-i18n` is used; Session storage is handled with `pinia`.
|
||||
|
||||
@ -41,6 +42,7 @@ The following commands are available:
|
||||
| **Test** | |
|
||||
| `npm run test:lint` | Run all linters |
|
||||
| `npm run test:lint:eslint` | Run linter eslint |
|
||||
| `npm run test:lint:locales`| Run linter locales |
|
||||
| `npm run test:lint:remark` | Run linter remark |
|
||||
| `npm run test:lint:style` | Run linter stylelint |
|
||||
| `npm run test:unit` | Run all unit tests and generate coverage report |
|
||||
@ -81,9 +83,7 @@ The following endpoints are provided given the right command is executed or all
|
||||
- [ ] figma
|
||||
- [ ] chromatic
|
||||
- [ ] github actions
|
||||
- [ ] lint locales
|
||||
- [ ] feature zähler -> pinia tore
|
||||
- [ ] lint style (inline vue) stylelint?
|
||||
|
||||
## Known Problems
|
||||
|
||||
@ -103,6 +103,9 @@ Currently none
|
||||
[badge-docker-img]: https://img.shields.io/badge/docker-latest-blue
|
||||
[badge-docker-href]: https://www.docker.com/
|
||||
|
||||
[badge-jq-img]: https://img.shields.io/badge/jq-latest-blue
|
||||
[badge-jq-href]: https://jqlang.github.io/jq/
|
||||
|
||||
[badge-vue-img]: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2FIT4Change%2Fboilerplate-frontend%2Fmaster%2Fpackage.json&query=dependencies.vue&label=vue&color=green
|
||||
[badge-vue-href]: https://vuejs.org/
|
||||
|
||||
|
||||
@ -2,8 +2,10 @@ import { createI18n } from 'vue-i18n'
|
||||
|
||||
// eslint-disable-next-line import/no-relative-parent-imports
|
||||
import de from '../src/locales/de'
|
||||
// import { de as $vuetify } from 'vuetify/locale'
|
||||
// eslint-disable-next-line import/no-relative-parent-imports
|
||||
import en from '../src/locales/en'
|
||||
// import { en as $vuetify } from 'vuetify/locale'
|
||||
|
||||
export default createI18n({
|
||||
legacy: false, // Vuetify does not support the legacy mode of vue-i18n
|
||||
|
||||
1
scripts/locales/keys.jq
Normal file
1
scripts/locales/keys.jq
Normal file
@ -0,0 +1 @@
|
||||
path(..)|[.[]|tostring]|join(".")
|
||||
44
scripts/locales/locales.sh
Executable file
44
scripts/locales/locales.sh
Executable file
@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
if [ $# -eq 0 ]
|
||||
then
|
||||
echo "You have to supply at least one argument specifying the folder to lint"
|
||||
fi
|
||||
|
||||
FILES="$1"
|
||||
|
||||
tmp=$(mktemp)
|
||||
exit_code=0
|
||||
|
||||
for locale_file in $FILES/*.json
|
||||
do
|
||||
jq -f $(dirname "$0")/sort.jq $locale_file > "$tmp"
|
||||
# check sort order and fix it if required
|
||||
if [ "$2" == "--fix" ]
|
||||
then
|
||||
mv "$tmp" $locale_file
|
||||
else
|
||||
if diff -q "$tmp" $locale_file > /dev/null ;
|
||||
then
|
||||
: # all good
|
||||
else
|
||||
exit_code=$?
|
||||
echo "$(basename -- $locale_file) is not sorted by keys"
|
||||
fi
|
||||
fi
|
||||
# check keys
|
||||
if [ -n "$LAST_FILE" ]; then
|
||||
listPaths="jq -f $(dirname "$0")/keys.jq"
|
||||
diffString="<( cat $LAST_FILE | $listPaths ) <( cat $locale_file | $listPaths )"
|
||||
if eval "diff -q $diffString";
|
||||
then
|
||||
: # all good
|
||||
else
|
||||
eval "diff -y $diffString | grep '[|<>]'";
|
||||
printf "\n$LAST_FILE\" and $locale_file translation keys do not match, see diff above.\n"
|
||||
exit_code=1
|
||||
fi
|
||||
fi
|
||||
LAST_FILE=$locale_file
|
||||
done
|
||||
|
||||
exit $exit_code
|
||||
13
scripts/locales/sort.jq
Normal file
13
scripts/locales/sort.jq
Normal file
@ -0,0 +1,13 @@
|
||||
def walk(f):
|
||||
. as $in
|
||||
| if type == "object" then
|
||||
reduce keys_unsorted[] as $key
|
||||
( {}; . + { ($key): ($in[$key] | walk(f)) } ) | f
|
||||
elif type == "array" then map( walk(f) ) | f
|
||||
else f
|
||||
end;
|
||||
|
||||
def keys_sort_by(f):
|
||||
to_entries | sort_by(.key|f ) | from_entries;
|
||||
|
||||
walk(if type == "object" then keys_sort_by(ascii_upcase) else . end)
|
||||
3
src/locales/de.json
Normal file
3
src/locales/de.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"counter": "Zähler"
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
import { de as $vuetify } from 'vuetify/locale'
|
||||
|
||||
export default {
|
||||
counter: 'Zähler',
|
||||
$vuetify,
|
||||
}
|
||||
3
src/locales/en.json
Normal file
3
src/locales/en.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"counter": "Counter"
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
import { en as $vuetify } from 'vuetify/locale'
|
||||
|
||||
export default {
|
||||
counter: 'Counter',
|
||||
$vuetify,
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user