npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@softkit/i18n

v0.4.5

Published

This library is a simple wrapper based on [nestjs-i18n](https://nestjs-i18n.com/)

Downloads

20

Readme

i18n library wrapper

This library is a simple wrapper based on nestjs-i18n

It has a few additions:

  • We highly encourage to use it in all apps and libraries, even if you do support only one language. The reason is simple, you can have all possible strings that your customers may see in one place, and this is awesome. Also you will be able to easily share general files across your teams if you have more than one, and your customers will have an amazing experience on your platform. Also one day you will receive a request from manager saying either we are expanding to new market or give me a list of all strings that we have in our app, and you will be able to do it in a few minutes.
  • it has a default config for i18n, to use in other apps and libraries (libraries usually can use this lib only for testing)
  • default response body formatter for exceptions, to follow RFC7807 standard

Installation

yarn add @softkit/i18n

Setup

Load module

import { setupI18nModule } from '@softkit/i18n';

@Module({
  imports: [setupI18nModule(__dirname)],
})
export class YourAppModule {}

Update your RootConfig class

import { I18nConfig } from '@softkit/i18n';

export default class RootConfig {
  @Type(() => I18nConfig)
  @ValidateNested()
  // field name doesn't matter, it only affect how you will configure it in your .env.yaml file
  public readonly i18n!: I18nConfig;
}

Update your .env.yaml file

Paths are relative to your app module file location

i18:
  paths:
    - i18n/
    - ../../../libs/validation/src/lib/i18n/
    - ../../../libs/exceptions/src/lib/i18n/

nestjs-i18n has a great client for types generation. Example will generate types to generated folder, this is super useful to do not miss any property in your translations

nestjs-i18n generate-types -t json -p ./src/lib/i18n -o ./src/lib/generated/i18n.generated.ts -w

TIP: Create utils file to use in your app, to get i18n typesafe and easy to use

import {
  i18nValidationMessage,
  i18nValidationMessageString,
} from '@softkit/i18n';
import { Path } from '@softkit/i18n/dist/types';
import { I18nTranslations } from '../generated/i18n.generated';

export function i18nString(key: Path<I18nTranslations>) {
  return i18nValidationMessageString<I18nTranslations>(key);
}

export function i18n(key: Path<I18nTranslations>, args?: unknown) {
  return i18nValidationMessage<I18nTranslations>(key, args);
}

This will make code cleaner and easier to read, you won't need to include types everytime when you want to use i18n