Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: merge master to main #3

Merged
merged 4 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading