-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add translate pipe and directive
- Loading branch information
1 parent
e336f1f
commit ac8e5c7
Showing
25 changed files
with
13,556 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Editor configuration, see https://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
max_line_length = off | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
node_modules/ | ||
src/main/docker/ | ||
jest.conf.js | ||
webpack/ | ||
target/ | ||
build/ | ||
node/ | ||
dist/ | ||
postcss.config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
{ | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": ["@angular-eslint/eslint-plugin", "@typescript-eslint"], | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:@typescript-eslint/recommended-requiring-type-checking", | ||
"plugin:@angular-eslint/recommended", | ||
"prettier", | ||
"eslint-config-prettier" | ||
], | ||
"env": { | ||
"browser": true, | ||
"es6": true, | ||
"commonjs": true | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2020, | ||
"sourceType": "module", | ||
"project": "./tsconfig.json" | ||
}, | ||
"rules": { | ||
"@angular-eslint/component-selector": [ | ||
"error", | ||
{ | ||
"type": "element", | ||
"prefix": "", | ||
"style": "kebab-case" | ||
} | ||
], | ||
"@angular-eslint/directive-selector": [ | ||
"error", | ||
{ | ||
"type": "attribute", | ||
"prefix": "", | ||
"style": "camelCase" | ||
} | ||
], | ||
"@angular-eslint/relative-url-prefix": "error", | ||
"@typescript-eslint/ban-types": [ | ||
"error", | ||
{ | ||
"extendDefaults": true, | ||
"types": { | ||
"{}": false | ||
} | ||
} | ||
], | ||
"@typescript-eslint/explicit-function-return-type": ["error", { "allowExpressions": true }], | ||
"@typescript-eslint/explicit-module-boundary-types": "off", | ||
"@typescript-eslint/member-ordering": [ | ||
"error", | ||
{ | ||
"default": [ | ||
"public-static-field", | ||
"protected-static-field", | ||
"private-static-field", | ||
"public-instance-field", | ||
"protected-instance-field", | ||
"private-instance-field", | ||
"constructor", | ||
"public-static-method", | ||
"protected-static-method", | ||
"private-static-method", | ||
"public-instance-method", | ||
"protected-instance-method", | ||
"private-instance-method" | ||
] | ||
} | ||
], | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/no-floating-promises": "off", | ||
"@typescript-eslint/no-non-null-assertion": "off", | ||
"@typescript-eslint/no-parameter-properties": ["warn", { "allows": ["public", "private", "protected"] }], | ||
"@typescript-eslint/no-shadow": ["error"], | ||
"@typescript-eslint/no-unnecessary-condition": "error", | ||
"@typescript-eslint/no-unsafe-argument": "off", | ||
"@typescript-eslint/no-unsafe-assignment": "off", | ||
"@typescript-eslint/no-unsafe-call": "off", | ||
"@typescript-eslint/no-unsafe-member-access": "off", | ||
"@typescript-eslint/prefer-nullish-coalescing": "error", | ||
"@typescript-eslint/prefer-optional-chain": "error", | ||
"@typescript-eslint/unbound-method": "off", | ||
"arrow-body-style": "error", | ||
"curly": "error", | ||
"eqeqeq": [ | ||
"error", | ||
"always", | ||
{ | ||
"null": "ignore" | ||
} | ||
], | ||
"guard-for-in": "error", | ||
"no-bitwise": "error", | ||
"no-caller": "error", | ||
"no-console": [ | ||
"error", | ||
{ | ||
"allow": ["warn", "error"] | ||
} | ||
], | ||
"no-eval": "error", | ||
"no-labels": "error", | ||
"no-new": "error", | ||
"no-new-wrappers": "error", | ||
"object-shorthand": [ | ||
"error", | ||
"always", | ||
{ | ||
"avoidExplicitReturnArrows": true | ||
} | ||
], | ||
"radix": "error", | ||
"spaced-comment": ["warn", "always"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [ 14.x, 16.x, 18.x ] | ||
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/ | ||
|
||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'npm' | ||
- run: npm install | ||
- run: npm run build:lib --if-present |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# See http://help.github.com/ignore-files/ for more about ignoring files. | ||
|
||
# Compiled output | ||
/dist | ||
/tmp | ||
/out-tsc | ||
/bazel-out | ||
|
||
# Node | ||
/node_modules | ||
npm-debug.log | ||
yarn-error.log | ||
|
||
# IDEs and editors | ||
.idea/ | ||
.project | ||
.classpath | ||
.c9/ | ||
*.launch | ||
.settings/ | ||
*.sublime-workspace | ||
|
||
# Visual Studio Code | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
.history/* | ||
|
||
# Miscellaneous | ||
/.angular/cache | ||
.sass-cache/ | ||
/connect.lock | ||
/coverage | ||
/libpeerconnection.log | ||
testem.log | ||
/typings | ||
|
||
# System files | ||
.DS_Store | ||
Thumbs.db | ||
/.angular/ | ||
/.vscode/ | ||
/yarn.lock | ||
/.scannerwork/ | ||
|
||
# Typescript generated files | ||
*.d.ts | ||
*.mjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
yarn lint-staged --allow-empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
'{,src/**/,webpack/}*.{md,json,yml,html,cjs,mjs,js,ts,tsx,css,scss}': ['prettier --write'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
node_modules | ||
target | ||
build | ||
package-lock.json | ||
.git | ||
.mvn | ||
gradle | ||
.gradle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Prettier configuration | ||
|
||
printWidth: 140 | ||
singleQuote: true | ||
tabWidth: 2 | ||
useTabs: false | ||
|
||
# js and ts rules: | ||
arrowParens: avoid | ||
|
||
# jsx and tsx rules: | ||
bracketSameLine: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# ngaTranslate | ||
|
||
**A wrapper for ngx-translate library that support default translate.** | ||
|
||
[![npm version](https://badge.fury.io/js/nga-translate.svg)](http://badge.fury.io/js/nga-translate) | ||
[![GitHub issues](https://img.shields.io/github/issues/mehrabisajad/nga-translate.svg)](https://github.com/mehrabisajad/nga-translate/issues) | ||
[![GitHub stars](https://img.shields.io/github/stars/mehrabisajad/nga-translate.svg)](https://github.com/mehrabisajad/nga-translate/stargazers) | ||
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/mehrabisajad/nga-translate/master/LICENSE) | ||
|
||
ngaTranslate is an Angular library that provides a pipe and directive to simplify the translation of text in your Angular applications. It is a wrapper for the popular ngx-translate library and provides additional features and convenience methods. | ||
|
||
## Installation | ||
|
||
To install ngaTranslate, run the following command in your terminal: | ||
|
||
``` | ||
npm install nga-translate --save | ||
``` | ||
|
||
## Usage | ||
|
||
### Pipe | ||
|
||
The ngaTranslate pipe can be used to translate text in your Angular templates. The pipe takes two and three arguments: | ||
|
||
#### 1. Three parameters: | ||
|
||
Translation key and an optional object of default translation and optional object of params. The default translation can be use if the key is not found. | ||
|
||
##### Examples | ||
|
||
```html | ||
{{ 'key' | ngaTranslate }} {{ 'key' | ngaTranslate : 'default translate' }} {{ 'key' | ngaTranslate : 'default translate' : { params } }} {{ | ||
'key' | ngaTranslate : 'default translate [{ p1 }]' : { p1: 'value' } }} {{ 'key' | ngaTranslate : { en: 'default translate [{ p1 }]', fr: | ||
'traduction par défaut [{ p1 }]' } : { p1: 'value' } }} | ||
``` | ||
|
||
#### 2. Two parameters: | ||
|
||
An optional object of default translation and optional object of params. The default translation can be use if the key is not found. | ||
|
||
##### Examples | ||
|
||
```html | ||
{{ { en: 'default translate' } | ngaTranslate } }} {{ { en: 'default translate [{ p1 }]' } | ngaTranslate : { p1: 'value' } }} {{ { en: | ||
'default translate [{ p1 }]', fr: 'traduction par défaut [{ p1 }]' } | ngaTranslate : { p1: 'value' } }} | ||
``` | ||
|
||
### Directive | ||
|
||
The ngaTranslate directive can be used to translate a key with valueTranslate and element's content. The element's content use for default translate. | ||
|
||
##### Examples | ||
|
||
```html | ||
<p ngaTranslate>Hello, world!</p> | ||
<p ngaTranslate="key">Hello, world!</p> | ||
<p ngaTranslate="key" [translateValues]="{ p1: 'value' }">Hello, world! [{ p1 }]</p> | ||
<p ngaTranslate="key" [translateValues]="{ p1: 'value' }"> | ||
{ en: 'Hello, world! [{ p1 }]', fr: 'Bonjour le monde! [{ p1 }]' } | ||
</p> | ||
``` | ||
|
||
### Features | ||
|
||
1. Simplified translation syntax: ngaTranslate provides a simpler syntax for translating text than ngx-translate. | ||
2. Default translations: ngaTranslate allows you to specify a default translation to use if the translation key is not found. | ||
3. Contextual translations: ngaTranslate allows you to provide additional context for translations, such as the current user's language or location. | ||
|
||
## Contributing | ||
|
||
We welcome contributions to ngaTranslate. Please feel free to create an issue or pull request on GitHub. | ||
|
||
## License | ||
|
||
ngaTranslate is licensed under the MIT License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"$schema": "./node_modules/@angular/cli/lib/config/schema.json", | ||
"version": 1, | ||
"newProjectRoot": "projects", | ||
"projects": { | ||
"nga-translate": { | ||
"root": "", | ||
"sourceRoot": "src", | ||
"projectType": "library", | ||
"architect": { | ||
"build": { | ||
"builder": "@angular-devkit/build-angular:ng-packagr", | ||
"options": { | ||
"project": "src/ng-package.json" | ||
}, | ||
"configurations": { | ||
"production": { | ||
"tsConfig": "src/tsconfig.lib.prod.json" | ||
}, | ||
"development": { | ||
"tsConfig": "src/tsconfig.lib.json" | ||
} | ||
}, | ||
"defaultConfiguration": "production" | ||
}, | ||
"test": { | ||
"builder": "@angular-devkit/build-angular:karma", | ||
"options": { | ||
"main": "src/test.ts", | ||
"tsConfig": "src/tsconfig.spec.json", | ||
"karmaConfig": "src/karma.conf.js" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"cli": { | ||
"analytics": false | ||
} | ||
} |
Oops, something went wrong.