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

@zauberware/react-i18n

v0.1.4

Published

Install Lokalise (https://github.com/lokalise/lokalise-cli-2-go)

Downloads

10

Readme

Requirements

Install Lokalise (https://github.com/lokalise/lokalise-cli-2-go)

Install

npm i @zauberware/react-i18n --save
yarn add @zauberware/react-i18n

Create Project

Create Project at https://lokalise.com. Copy token and project id to your .env file. Go to personal profile to grap token and to project settings to grap project id.

.env

Configure and put these env variables to your .env file.

Common

REACT_APP_LOKALISE_TOKEN=token
REACT_APP_LOKALISE_PROJECT_ID=projectid
REACT_APP_BRANCHES=false
REACT_APP_LOCALES=["de", "en", "fr"]
REACT_APP_DEFAULT_LOCALE=de
REACT_APP_ENV=development
REACT_APP_S3_BUCKET=zwt.locales.test/lokalise
REACT_APP_SRC_INPUT=./src/**/*.js

React

REACT_APP_LOCALES_BUILD_PATH=public/locales
REACT_APP_LOCALES_PUSH_PATH=./.locales
REACT_APP_ENV=development

React-Native

REACT_APP_LOCALES_BUILD_PATH=www/locales
REACT_APP_LOCALES_PUSH_PATH=.locales

package.json scripts

Put these scripts into your root package.json

"locales-push": "npm explore @zauberware/react-i18n -- npm run locales-push --env=$PWD",
"locales-parse": "npm explore @zauberware/react-i18n -- npm run locales-parse --env=$PWD",
"locales-push-files": "npm explore @zauberware/react-i18n -- npm run locales-push-files --env=$PWD",
"locales-pull-files": "npm explore @zauberware/react-i18n -- npm run locales-pull-files --env=$PWD"

Develop your app!

React

import React, { Suspense } from "react";

<Suspense fallback="Loading">
    <App />
</Suspense>
import i18n, { useTranslation } from "@zauberware/react-i18n/web";
const { t } = useTranslation("app", { useSuspense: true });

{t('key')}
{t('key', {maxLength: 150})}

{t('key', {defaultValue: 'XYZ'})} // helps coding a lot!

React Native

import i18n, { useTranslation } from "@zauberware/react-i18n/mobile";

Flows

Create locales

Based on the env variable "REACT_APP_LOCALES", it will create the locales you want to use for your project. You can re-run this command if you want to add locales.

npm run locales-push

Use branches [optional]

Go to project settings. Check "branching", save. Create branches you need e.g. development, staging, production. Set env variable "REACT_APP_BRANCHES" to true to tell React to download env specific translations. Set "REACT_APP_ENV" to the env you are currently using.

All package.json commands need to add --branch=staging to tell Lokalise which env we are talking to.

Parse translation keys

Will create parsed files to upload/compare with Lokalise. You can configure where the parser should create the files with "REACT_APP_LOCALES_PUSH_PATH". These files be used to push/cleanup keys. The format of these JSON files is structured. Parser will collect keys, validation limits etc.

npm run locales-parse

Push translation keys

Push translations keys/files from "REACT_APP_LOCALES_PUSH_PATH".

npm run locales-push-files

Go to your lokalise project and check whether the upload was successful.

Pull translation keys

Pull keys to directory. Please use public/locales for React web projects! You have to pull locales, otherwise fallback files won't work! These files will be put into the build as fallback JSON files. The format of these JSON files is flat (key: value).

npm run locales-pull-files

S3 Bucket sync

Enable S3 Integration in your lokalise project.

Specify which bucket should be used declared with "REACT_APP_S3_BUCKET". Bucket needs to be public!

You can trigger s3 sync by clicking "Download" and selecting "Amazon S3" as export.

Please use project_id/%LANG_ISO% as file structure. Please use project_id/env/%LANG_ISO% when using branches. Please use format "JSON (.json)"! Click "build only" to trigger s3.

You can ask support to enable s3 sync on other events like "translations updated".

Translator Role

Create Translator User + Translator Role, which limitted permissions. Can only edit locales. Cannot create locales or create keys. Invite client to start translating.

Cleanup keys

Generate keys npm run locales-parse.

npm run locales-push-files --cleanup=true will remove all remote keys which do not exist anymore