You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<palign="center"> <b>nestjs-cls-translation</b> provides context-aware translations in NestJS applications using <b>Context-Local Storage</b> (CLS), making it easier to manage and access locale-specific data across different parts of your application.</p>
6
+
7
+
## Installation 🤖
8
+
9
+
Install the `nestjs-cls-translation` package with:
This will return the translated string based on the user's current language, or the fallback language if no specific translation exists for the user's language.
40
+
41
+
#### Get Current Language
42
+
43
+
To retrieve the language currently being used in the context of a request, use the `currentLanguage()` function:
44
+
45
+
```typescript
46
+
const currentLang =currentLanguage()
30
47
```
31
48
32
-
# Run with a language
49
+
#### Get Default Language
50
+
51
+
If you need to access the application's default or fallback language (set in the module configuration), use the `defaultLanguage()` function:
52
+
53
+
```typescript
54
+
const defaultLang =defaultLanguage()
33
55
```
34
-
await runInLanguage('en', () => ...);
56
+
57
+
#### Run with a Specific Language Context
58
+
59
+
You may want to execute certain parts of your code in a specific language context. The runInLanguage() function allows you to run a block of code under a designated language context, overriding the current language:
0 commit comments