localized-strings
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -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). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20013
171