0.3.39 • Published 12 days ago

@anchan828/nest-i18n-i18next v0.3.39

Weekly downloads
464
License
MIT
Repository
github
Last release
12 days ago

@anchan828/nest-i18n-i18next

npm NPM

Description

i18n module for i18next

Installation

$ npm i --save @anchan828/nest-i18n-i18next i18next

Quick Start

Importing module

@Module({
  imports: [
    I18nextModule.register({
      fallbackLng: ["en"],
      resources: {
        en: {
          translation: { test: "Test" },
        },
        jp: {
          translation: { test: "テスト" },
        },
      },
    }),
  ],
})
export class AppModule {}

Basic usage

@Controller()
class TestController {
  @Get("test")
  public test(@Headers("accept-language") acceptLanguage: string): string {
    return i18next.t("test", { lng: acceptLanguage });
  }
}

Using with controller

Use I18nExceptionFilter

import { I18nExceptionFilter, I18nNotFoundException } from "@anchan828/nest-i18n-i18next";

@Controller()
@UseFilters(I18nExceptionFilter)
class TestController {
  @Get("error")
  public i18nError(): Promise<string> {
    throw new I18nNotFoundException({ key: "test" });
  }
}

Using with GraphQL

Use I18nExceptionFilter

import { I18nExceptionFilter, I18nNotFoundException } from "@anchan828/nest-i18n-i18next";

@Resolver("User")
@UseFilters(I18nExceptionFilter)
export class RootUserQueryResolver {
  @Query()
  public async user(@Args("id") id: string): Promise<Nullable<UserEntity>> {
    throw new I18nNotFoundException({ key: "test" });
  }
}

Set Accept-Language header

You need to set Accept-Language header for detecting language.

npm.io

Note

There are wrapped exception classes for i18n. See ./src/exceptions.t

This package is using i18next-fs-backend for loading translations from static files.

I18nextModule.register({
  fallbackLng: ["en"],
  backend: {
    loadPath: "/locales/{{lng}}/{{ns}}.json",
  },
});

License

MIT

0.3.39

12 days ago

0.3.38

19 days ago

0.3.37

26 days ago

0.3.36

1 month ago

0.3.31

2 months ago

0.3.30

2 months ago

0.3.35

1 month ago

0.3.34

2 months ago

0.3.33

2 months ago

0.3.32

2 months ago

0.3.29

3 months ago

0.3.28

3 months ago

0.3.20

5 months ago

0.3.27

3 months ago

0.3.26

4 months ago

0.3.25

4 months ago

0.3.24

4 months ago

0.3.23

4 months ago

0.3.22

5 months ago

0.3.21

5 months ago

0.3.19

5 months ago

0.3.18

6 months ago

0.3.17

6 months ago

0.3.16

6 months ago

0.3.15

6 months ago

0.3.14

6 months ago

0.3.13

7 months ago

0.3.12

7 months ago

0.3.11

7 months ago

0.3.10

7 months ago

0.3.9

8 months ago

0.3.8

8 months ago

0.3.7

9 months ago

0.3.6

9 months ago

0.3.5

9 months ago

0.3.4

10 months ago

0.3.3

10 months ago

0.3.2

10 months ago

0.3.1

10 months ago

0.3.0

10 months ago

0.2.44

11 months ago

0.2.43

11 months ago

0.2.42

11 months ago

0.2.41

11 months ago

0.2.40

12 months ago

0.2.39

12 months ago

0.2.38

12 months ago

0.2.37

1 year ago

0.2.36

1 year ago

0.2.35

1 year ago

0.2.34

1 year ago

0.2.33

1 year ago

0.2.32

1 year ago

0.2.31

1 year ago

0.2.30

1 year ago

0.2.29

1 year ago

0.2.28

1 year ago

0.2.27

1 year ago

0.2.26

1 year ago

0.2.25

1 year ago

0.2.24

1 year ago

0.2.23

1 year ago

0.2.22

1 year ago

0.2.21

1 year ago

0.2.20

1 year ago

0.2.19

1 year ago

0.2.18

1 year ago

0.2.17

1 year ago

0.2.16

1 year ago

0.2.15

1 year ago

0.2.14

1 year ago

0.2.13

1 year ago

0.2.12

1 year ago

0.2.11

2 years ago

0.2.10

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.32

2 years ago

0.1.31

2 years ago

0.1.30

2 years ago

0.1.29

2 years ago

0.1.28

2 years ago

0.1.27

2 years ago

0.1.26

2 years ago

0.1.25

2 years ago

0.1.24

2 years ago

0.1.23

2 years ago

0.1.22

2 years ago

0.1.21

2 years ago

0.1.20

2 years ago

0.1.19

2 years ago

0.1.18

2 years ago

0.1.17

2 years ago

0.1.16

2 years ago

0.1.15

2 years ago

0.1.14

2 years ago

0.1.13

2 years ago

0.1.12

2 years ago

0.1.11

2 years ago

0.1.10

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.2

2 years ago

0.1.3

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.24

2 years ago

0.0.23

2 years ago

0.0.22

2 years ago

0.0.21

2 years ago

0.0.20

2 years ago

0.0.19

2 years ago

0.0.18

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago

0.0.0

3 years ago