Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

localized-strings

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

localized-strings - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

2

lib/LocalizedStrings.d.ts

@@ -11,3 +11,3 @@ declare module 'localized-strings' {

interface LocalizedStringsMethods {
export interface LocalizedStringsMethods {
setLanguage(language: string): void;

@@ -14,0 +14,0 @@ getLanguage(): string;

{
"name": "localized-strings",
"version": "0.0.2",
"version": "0.0.3",
"description": "Simple module to localize the strings of any JS based program using the same syntax used in the ReactLocalization and ReactNativeLocalization module, use 'npm run build' before publishing",

@@ -5,0 +5,0 @@ "scripts": {

@@ -51,3 +51,3 @@ # localized-strings

The default method check the browser language but it could be replaced with other check if you are in a Server, ReactNative or Nativescript project.
The default method check the browser language but it could be replaced with other check if you are in a Server, ReactNative or [Nativescript](https://www.nativescript.org) project.

@@ -77,2 +77,20 @@ The getInterfaceLanguage method can be as simple as:

### Nativescript example
This is how you can use the library in a [Nativescript](https://www.nativescript.org) project
```js
const platform = require("platform");
this.strings = new LocalizedStrings({
it: {
score: "Punti",
time: "Tempo"
},
en: {
score: "Score",
time: "Time"
}
}, () => {
return platform.device.language;
}
);
```
## API

@@ -124,3 +142,32 @@

## Typescript support
Because of the dynamically generated class properties, it's a little tricky to have the autocomplete functionality working.
Anyway it's possible to gain the desired results by:
1. defining an Interface that extends the LocalizedStringsMethods interface and has all the object string's keys
2. defining that the LocalizedStrings instance implements that interface
This is the suggested solution to work with Typescript:
```js
export interface IStrings extends LocalizedStringsMethods{
score:string;
time: String;
}
public strings: IStrings;
this.strings = new LocalizedStrings({
it: {
score: "Punti",
time: "Tempo"
},
en: {
score: "Score",
time: "Time"
}
});
```
## Questions or suggestions?
Feel free to contact me on [Twitter](https://twitter.com/talpaz) or [open an issue](https://github.com/stefalda/localized-strings/issues/new).
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc