Skip to content

Commit

Permalink
Merge pull request #3 from hodfords-solutions/master
Browse files Browse the repository at this point in the history
feat: merge master to main
  • Loading branch information
hodfords-phuong-vo-be authored Aug 27, 2024
2 parents f7117fd + ffb0b48 commit 27023d1
Show file tree
Hide file tree
Showing 11 changed files with 6,802 additions and 2,778 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Publish Package to npmjs
on:
push:
branch:
- main
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -14,6 +14,7 @@ jobs:
registry-url: 'https://registry.npmjs.org'
- run: npm install
- run: npm run build
- run: cp README.md dist/
- run: cd dist && npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
4 changes: 3 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install lint-staged
changedFiles="$(git diff --name-only --cached)"
npm run cspell --no-must-find-files ${changedFiles}
npm run lint-staged
2 changes: 1 addition & 1 deletion .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"libs/**/*.ts": ["prettier --write"]
"libs/**/*.ts": ["eslint --fix --max-warnings 0"]
}
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"useTabs": false,
"trailingComma": "none",
"bracketSpacing": true,
"jsxBracketSameLine": false,
"bracketSameLine": false,
"semi": true,
"endOfLine": "auto"
}
7 changes: 7 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"version": "0.2",
"language": "en",
"words": ["nestjs", "middlewares", "hodfords", "postbuild"],
"flagWords": ["hte"],
"ignorePaths": ["node_modules", "test", "*.spec.ts", "cspell.json"]
}
4 changes: 2 additions & 2 deletions libs/helpers/translation.helper.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { TranslationService } from '../services/translation.service';
import cls from '@hodfords/cls-hooked';
import {
CLS_TRANSLATION_NAMESPACE,
CLS_TRANSLATION_NAMESPACE_NAME
} from '../constants/cls-translation-namespace.constant';
import { IS_FULL_LANGUAGE } from '../constants/language-key.constant';
import { TranslationService } from '../services/translation.service';
import { RunInLanguageParams, TranslateOptions } from '../types';
import cls from '@hodfords/cls-hooked';

export function trans(key: string, options: TranslateOptions = {}) {
return TranslationService.instance.translate(key, options);
Expand Down
2 changes: 1 addition & 1 deletion libs/middlewares/translation.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Injectable, NestMiddleware } from '@nestjs/common';
import { NextFunction, Request, Response } from 'express';
import { TranslationService } from '../services/translation.service';
import { CLS_TRANSLATION_NAMESPACE } from '../constants/cls-translation-namespace.constant';
import { runInLanguage } from '../helpers/translation.helper';
import { TranslationService } from '../services/translation.service';

@Injectable()
export class TranslationMiddleware implements NestMiddleware {
Expand Down
11 changes: 7 additions & 4 deletions libs/services/translation.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ExecutionContext, Injectable } from '@nestjs/common';
import { I18N_OPTIONS, I18nOptions, I18nService } from 'nestjs-i18n';
import { ModuleRef } from '@nestjs/core';
import { I18nOptions, I18nService, I18N_OPTIONS } from 'nestjs-i18n';
import { CLS_RESOLVERS, CLS_TRANSLATION_NAMESPACE, DEFAULT_LANGUAGE_KEY, PRIORITY_LANGUAGE_GETTER } from '../constants';
import { LanguageKeyMap, TranslateOptions } from '../types';
import { ClsResolver } from '../interfaces';
import { LanguageKeyMap, TranslateOptions } from '../types';

@Injectable()
export class TranslationService {
Expand All @@ -14,7 +14,10 @@ export class TranslationService {
private defaultLanguageKey: string;
private priorityLanguageGetter: () => string;

constructor(private i18nService: I18nService, private moduleRef: ModuleRef) {
constructor(
private i18nService: I18nService<Record<string, string>>,
private moduleRef: ModuleRef
) {
TranslationService.instance = this;
this.clsResolvers = this.moduleRef.get(CLS_RESOLVERS, { strict: false });
this.i18nOptions = this.moduleRef.get(I18N_OPTIONS, { strict: false });
Expand All @@ -35,7 +38,7 @@ export class TranslationService {
options.lang = this.getCurrentLanguage();
}

return this.i18nService.translate<string>(key, options);
return this.i18nService.translate(key, options);
}

getDefaultLanguageKey() {
Expand Down
Loading

0 comments on commit 27023d1

Please sign in to comment.