
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Tiny experimental i18n library for JavaScript using [tagged template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals).
Tiny experimental i18n library for JavaScript using tagged template literals.
I'm starting small and evolving as the need arises.
You can try out the API on RunKit without installing the library.
Install the library using npm
or yarn
:
npm install nano-i18n
yarn add nano-i18n
You can load the library through a <script>
tag using unpkg.com
:
<script src='https://unpkg.com/nano-i18n'></script>
import { load, k, v, t } from 'nano-i18n';
// 1. Load some translations
// Simple replacement
load(k`Hello, ${'World'}!`, v`Salut, ${0}!`);
// Swap the order of values in the translation
load(k`My name is ${'mine'}, yours is ${'yours'}`, v`Your name is ${1}, mine is ${0}`);
// 2. Translate some messages
console.log(t`Hello, ${'Dan'}!`);
// => "Salut, Dan!"
console.log(t`My name is ${'Dan'}, yours is ${'Alex'}`);
// => "Your name is Alex, mine is Dan"
§ load(key: string, value: string | function)
Set up a translation:
import { load } from 'nano-i18n';
load(k`Hello, ${'World'}!`, v`Salut, ${0}!`);
You can also add a batch of translations:
import { load } from 'nano-i18n';
let translations = {};
translations[k`Hello, ${'World'}!`] = v`Salut, ${0}!`;
translations[k`My name is ${'name'}`] = v`Numele meu este ${0}`;
load(translations);
Or using the computed property names syntax:
import { load } from 'nano-i18n';
load({
[k`Hello, ${'World'}!`]: v`Salut, ${0}!`,
[k`My name is ${'name'}`]: v`Numele meu este ${0}`
});
Or skipping the k
literal tag altogether and using a string key directly:
import { load } from 'nano-i18n';
load('Hello, {}!', v`Salut, ${0}!`);
You can also skip the v
literal tag and send a simple string translation:
import { load } from 'nano-i18n';
load('Hello, World!', 'Salut, lume!');
§ clear()
Clears all the translations:
import { clear } from 'nano-i18n';
clear();
§ config(options: object)
Configures the library. Available options:
log (Number, default 0
)
The log level for the library. Possible values:
0
disables logging1
logs a warning in the console on a missing translation2
throws an error when encountering a missing translationplaceholder (String, default {}
)
The string to use as placeholder for interpolated values when generating the key for a translation.
§ k
Obtains the key for a certain literal:
import { k } from 'nano-i18n';
k`Hello, ${'World'}`;
// => "Hello, {}"
Keys are generated by replacing all values with the {}
sequence.
Note: That means that currently, the strings you wish to translate may not contain the {}
sequence.
You may change this by using the config
method:
import { config } from 'nano-i18n';
config({
placeholder: '@@'
});
§ v
Generates a translation function for a literal:
import { v } from 'nano-i18n';
v`Salut, ${0}!`;
// => function(strings, values) {}
When providing a translation, the interpolated values need to be numbers (i.e. ${0}
, ${1}
, et cetera). They don't necessarily need to be in sequential order, so you can swap them around if the translation needs it.
§ t
Get a translated string:
import { t } from 'nano-i18n';
t`Hello, ${'Dan'}!`;
// => "Salut, Dan!"
If there's no translation available, it returns the normal interpolated string instead, and logs a warning to the console.
You can also use t
as a normal function for translating dynamic strings:
import { t } from 'nano-i18n';
t('Hello World');
This is useful for passing the t
function to templating languages such as Mustache.
FAQs
Tiny experimental i18n library for JavaScript using tagged template literals.
The npm package nano-i18n receives a total of 11 weekly downloads. As such, nano-i18n popularity was classified as not popular.
We found that nano-i18n demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.