diff --git a/.github/workflows/publish-npm.yaml b/.github/workflows/publish-npm.yaml new file mode 100644 index 0000000..02a3600 --- /dev/null +++ b/.github/workflows/publish-npm.yaml @@ -0,0 +1,23 @@ +name: Publish NPM package +on: workflow_dispatch +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: '16.x' + registry-url: 'https://registry.npmjs.org/' + always-auth: true + scope: '@hetznercloud' + - name: ls config + run: npm config ls -l + - name: install dependencies + run: yarn install --frozen-lockfile + - name: build + run: yarn build + - name: publish + run: cd ./dist/ngx-translate-mock && npm publish + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/projects/ngx-translate-mock/package.json b/projects/ngx-translate-mock/package.json index 5c36d25..dbd9415 100644 --- a/projects/ngx-translate-mock/package.json +++ b/projects/ngx-translate-mock/package.json @@ -2,10 +2,13 @@ "name": "@hetznercloud/ngx-translate-mock", "repository": "https://github.com/hetznercloud/ngx-translate-mock", "license": "MIT", - "version": "1.0.0", + "version": "1.1.0", "peerDependencies": { "@angular/core": ">=14", "@ngx-translate/core": "^14.0.0", "rxjs": ">=6" + }, + "publishConfig": { + "@hetznercloud:registry": "https://registry.npmjs.org/@hetznercloud" } } diff --git a/projects/ngx-translate-mock/src/lib/ngx-translate-mock.service.ts b/projects/ngx-translate-mock/src/lib/ngx-translate-mock.service.ts index 6c0865f..1705da6 100644 --- a/projects/ngx-translate-mock/src/lib/ngx-translate-mock.service.ts +++ b/projects/ngx-translate-mock/src/lib/ngx-translate-mock.service.ts @@ -24,8 +24,10 @@ export class TranslateServiceMock { languages: string[] = ['de']; - get(content: string): Observable { - return of(TRANSLATED_STRING + content); + get(content: string | Array, interpolateParams?: Object): Observable { + return typeof content === 'string' + ? of(TRANSLATED_STRING + content) + : of(this._translateArray(content)); } use(lang: string): void { @@ -50,11 +52,20 @@ export class TranslateServiceMock { return of({}); } - instant(key: string | string[], interpolateParams?: object): string { - return TRANSLATED_STRING + key.toString(); - } + instant(content: string | Array, interpolateParams?: Object): string | any { + return typeof content === 'string' + ? TRANSLATED_STRING + content + : this._translateArray(content); + } setDefaultLang(lang: string): void { this.onDefaultLangChangeSubject.next(lang); } + + private _translateArray(content: string[]): Record { + return content.reduce((result, item) => { + result[item] = TRANSLATED_STRING + item; + return result; + }, {} as Record); + } } diff --git a/yarn.lock b/yarn.lock index bd05e1a..9404514 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3079,9 +3079,9 @@ debug@^3.2.6: ms "^2.1.1" decode-uri-component@^0.2.0: - version "0.2.0" - resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545" - integrity sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU= + version "0.2.2" + resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.2.tgz#e69dbe25d37941171dd540e024c444cd5188e1e9" + integrity sha512-FqUYQ+8o158GyGTrMFJms9qh3CqTKvAqgqsTnkLI8sKu0028orqBhxNMFkFen0zGyg6epACD32pjVk58ngIErQ== deep-is@^0.1.3: version "0.1.4"