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

@informaticon/base-i18n

v0.3.0

Published

i18n client lib

Downloads

8

Readme

lib.npm.base.i18n

I18n client library, published to npm as @information/base-i18n.

Prerequisites

Your project is already prepared to use npm packages, and you already have a bundler like Webpack, Rollup, or something similar set up. If you are unsure on how to set that up in a Play! project, check out the internal Using Webpack with Play! Framework guide.

Your project should use lib.play.base.i18n with version >=v1.3.0.

Usage

Install the package via npm

npm i @informaticon/base-i18n -D

Add svelte as dependency to your project (if not already added).

npm i svelte -D

Import the I18nMessages in your Loader and init the store in the DOMContentLoaded Event to make sure, that all messages will be loaded before you use it in JavaScript.

import { I18nMessages } from "@informaticon/base-i18n";

export class Loader {
    constructor() {
        document.addEventListener("DOMContentLoaded", this.ready);
    }

    protected async ready() {
        await I18nMessages.init();
    }
}

With the get function you can load the texts in Typescript.

import { I18nMessages } from "@informaticon/base-i18n";

// if no message for the key is found the key will be returned as message
let message = I18nMessages.get("IAM_APPLICATION_SVC_WEB_TICKET_TITLE");

// you can load a message with params (if you use more arguments than found in the Message there will be no error)
let message2 = I18nMessages.get("IAM_PERMISSIONS_COUNT_DYNAMIC", "2", "3", "2");

In Svelte you can subscribe directly to the store function. So if a message changes the displayed text will automatically be updated, too.

<script>
    import {getI18nMessage} from "@informaticon/base-i18n";

    export let msgKey = "";
    export let args = [];
</script>

{$getI18nMessage(msgKey, ...args)}

As an alternative you can use the I18nMessage.svelte component. Internally it uses a svelte store, so if a message changes the text will automatically be updated, too.

<script>
    import I18nMessage from "@informaticon/base-i18n/I18nMessage.svelte";
</script>

<I18nMessage msgKey={"IAM_APPLICATION_SVC_WEB_TICKET_TITLE"} />

If you want this feature in typescript also it is possible to subscribe to the store function. But be aware to unsubscribe from the store to prevent memory leaks!

import {getI18nMessage} from "@informaticon/base-i18n";

let getFunction;

const unsubscribe = getI18nMessage.subscribe(value => {
    getFunction = value;
});
console.log(getFunction("IAM_APPLICATION_SVC_WEB_TICKET_TITLE"));
document.addEventListener("pagehide", unsubscribe)

Contribution

Commands

package the project

npm run package

only code in created package folder must be published to npm

Test

:bulb: you have to use lib.play.base.i18n >=v1.3.0 in your test project

ToDo: maybe use npm link and not the files in the test project?

  1. Package this project with npm run package so your changes are compiled
  2. Import the local build in your test project
// for development purposes, don't commit this
import {I18nMessages} from '../../../../Projekte/lib/lib.npm.base.i18n/package/I18nMessages';
  1. When you are done, make sure that you change the imports back to the ones you'd use in production
// in production
import { I18nMessages } from "@informaticon/base-i18n/I18nMessages";

test with npm link

  1. cd to package and run npm link
  2. start the test project
  3. call npm link @inforamticon/base-i18n in your test project (important: do this after start, because with for eg. webpack plugin the npm i will be called on start)