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

@inlang/plugin-i18next

v4.13.37

Published

This plugin works with [i18next](https://inlang.com/m/kl95463j) to read and write messages. It also determines how translation functions and namespaces are parsed and handled by [Sherlock](https://inlang.com/m/r7kp499g/app-inlang-ideExtension) – a helpful

Downloads

820

Readme

What does this plugin do?

This plugin works with i18next to read and write messages. It also determines how translation functions and namespaces are parsed and handled by Sherlock – a helpful i18n VS Code extension.

Manual Installation

We recommend using the install button, but if you want to do it manually:

  • Add this to the modules in your project.inlang/settings.json
  • Change the sourceLanguageTag if needed
  • Include existing languagetags in the languageTags array
{
	"sourceLanguageTag": "en",
	"languageTags": ["en", "de"], 
	"modules": [
		"https://cdn.jsdelivr.net/npm/@inlang/plugin-i18next@latest/dist/index.js"
  	],
	"plugin.inlang.i18next": {
		"pathPattern": "./resources/{languageTag}.json"
  	}
}

Settings

The plugin offers further configuration options that can be passed as arguments. The following settings exist:

type PluginSettings = {
	pathPattern: string | { [key: string]: string }
	variableReferencePattern?: [string] | [string, string]
	sourceLanguageFilePath?: string
}

pathPattern

To use our plugin, you need to provide a path to the directory where your language-specific files are stored. Use the dynamic path syntax {languageTag} to specify the language name.

pathPattern without namespaces

"plugin.inlang.i18next": {
	"pathPattern": "./resources/{languageTag}.json"
}

pathPattern with namespaces

"plugin.inlang.i18next": {
	"pathPattern": {
		"common": "./resources/{languageTag}/common.json",
		"vital": "./resources/{languageTag}/vital.json"
	}
}

key (prefix): is prefixing the key with a colon values (path): is the path to the namespace resources

variableReferencePattern

Defines the pattern for variable references. The default is how i18next suggests the usage of placeholders.

default:

"plugin.inlang.i18next": {
	"variableReferencePattern": ["{{", "}}"]
}

sourceLanguageFilePath

This setting is optional and should only be used if the file name of your sourceLanguageTag does not match your pathPattern structure. For example, if your sourceLanguageTag is en but your sourceLanguage file is called main.json, you can use this setting to specify the path to the sourceLanguage file. Our recommendation is to rename the file to en.json and not use this setting.

Without namespaces

"plugin.inlang.i18next": {
	"sourceLanguageFilePath": "./resources/main.json"
}

With namespaces

"plugin.inlang.i18next": {
	"sourceLanguageFilePath": {
		"common": "./resources/main/common.json",
		"vital": "./resources/main/vital.json"
	}
}

Install the Inlang Visual Studio Code extension (Sherlock) to supercharge your i18n workflow

The plugin automatically informs Sherlock how to extract keys and namespaces from your code in order to display inline annotations. A quick run through of the most important features can be found here (loom). Install: VS Code Marketplace.

In-code usage

t("key")

With namespaces:

t("namespace:key") or t("key", { ns: "namespace" })

To learn about namespaces and how to use translation functions in your code, you can refer to i18next documentation. The plugin is capable of parsing the code and providing the IDE-extension with this information.

Expected behavior

The message IDs are sorted in the order in which they appear in the sourceLanguage file. The nesting or flattening of IDs is detected on a file-by-file basis. If the sourceLanguage file contains nested IDs, the plugin will also create nested IDs in the targetLanguage files. If the sourceLanguage file contains flattened IDs, the plugin will also create flattened IDs in the targetLanguage files.

Contributing

Getting started

Run the following commands in your terminal (node and npm must be installed):

  1. npm install
  2. npm run dev

npm run dev will start the development environment which automatically compiles the src/index.ts files to JavaScript (dist/index.js), runs tests defined in *.test.ts files and watches changes.

Publishing

Run npm run build to generate a build.

The dist directory is used to distribute the plugin directly via CDN like jsDelivr. Using a CDN works because the inlang config uses dynamic imports to import plugins.

Read the jsDelivr documentation on importing from GitHub.


Is something unclear or do you have questions? Reach out to us in our Discord channel or open a Discussion or an Issue on Github.