@nextcloud/l10n
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -11,3 +11,6 @@ module.exports = { | ||
], | ||
] | ||
], | ||
"plugins": [ | ||
"transform-class-properties", | ||
], | ||
}; |
@@ -5,2 +5,9 @@ # Changelog | ||
## 1.1.0 - 2020-02-21 | ||
### Added | ||
- Gettext-based translation helpers for Nextcloud-independent translations (mostly for libraries) | ||
### Changed | ||
- Updated documentation | ||
- Updated dependencies | ||
## 1.0.1 - 2020-01-08 | ||
@@ -7,0 +14,0 @@ ### Fixed |
var typedoc = typedoc || {}; | ||
typedoc.search = typedoc.search || {}; | ||
typedoc.search.data = {"kinds":{"64":"Function"},"rows":[{"id":0,"kind":64,"name":"getLocale","url":"globals.html#getlocale","classes":"tsd-kind-function"},{"id":1,"kind":64,"name":"getLanguage","url":"globals.html#getlanguage","classes":"tsd-kind-function"},{"id":2,"kind":64,"name":"translate","url":"globals.html#translate","classes":"tsd-kind-function"},{"id":3,"kind":64,"name":"translatePlural","url":"globals.html#translateplural","classes":"tsd-kind-function"},{"id":4,"kind":64,"name":"getFirstDay","url":"globals.html#getfirstday","classes":"tsd-kind-function"},{"id":5,"kind":64,"name":"getDayNames","url":"globals.html#getdaynames","classes":"tsd-kind-function"},{"id":6,"kind":64,"name":"getDayNamesShort","url":"globals.html#getdaynamesshort","classes":"tsd-kind-function"},{"id":7,"kind":64,"name":"getDayNamesMin","url":"globals.html#getdaynamesmin","classes":"tsd-kind-function"},{"id":8,"kind":64,"name":"getMonthNames","url":"globals.html#getmonthnames","classes":"tsd-kind-function"},{"id":9,"kind":64,"name":"getMonthNamesShort","url":"globals.html#getmonthnamesshort","classes":"tsd-kind-function"}]}; | ||
typedoc.search.data = {"kinds":{"32":"Variable","64":"Function","128":"Class","256":"Interface","512":"Constructor","1024":"Property","2048":"Method","65536":"Type literal"},"rows":[{"id":0,"kind":256,"name":"TranslationOptions","url":"interfaces/translationoptions.html","classes":"tsd-kind-interface"},{"id":1,"kind":1024,"name":"escape","url":"interfaces/translationoptions.html#escape","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"TranslationOptions"},{"id":2,"kind":32,"name":"OC","url":"globals.html#oc","classes":"tsd-kind-variable"},{"id":3,"kind":32,"name":"window","url":"globals.html#window","classes":"tsd-kind-variable"},{"id":4,"kind":64,"name":"getLocale","url":"globals.html#getlocale","classes":"tsd-kind-function"},{"id":5,"kind":64,"name":"getLanguage","url":"globals.html#getlanguage","classes":"tsd-kind-function"},{"id":6,"kind":64,"name":"translate","url":"globals.html#translate","classes":"tsd-kind-function"},{"id":7,"kind":64,"name":"translatePlural","url":"globals.html#translateplural","classes":"tsd-kind-function"},{"id":8,"kind":64,"name":"getFirstDay","url":"globals.html#getfirstday","classes":"tsd-kind-function"},{"id":9,"kind":64,"name":"getDayNames","url":"globals.html#getdaynames","classes":"tsd-kind-function"},{"id":10,"kind":64,"name":"getDayNamesShort","url":"globals.html#getdaynamesshort","classes":"tsd-kind-function"},{"id":11,"kind":64,"name":"getDayNamesMin","url":"globals.html#getdaynamesmin","classes":"tsd-kind-function"},{"id":12,"kind":64,"name":"getMonthNames","url":"globals.html#getmonthnames","classes":"tsd-kind-function"},{"id":13,"kind":64,"name":"getMonthNamesShort","url":"globals.html#getmonthnamesshort","classes":"tsd-kind-function"},{"id":14,"kind":128,"name":"GettextBuilder","url":"classes/gettextbuilder.html","classes":"tsd-kind-class"},{"id":15,"kind":1024,"name":"locale","url":"classes/gettextbuilder.html#locale","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"GettextBuilder"},{"id":16,"kind":1024,"name":"translations","url":"classes/gettextbuilder.html#translations","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"GettextBuilder"},{"id":17,"kind":65536,"name":"__type","url":"classes/gettextbuilder.html#translations.__type","classes":"tsd-kind-type-literal tsd-parent-kind-property","parent":"GettextBuilder.translations"},{"id":18,"kind":2048,"name":"setLanguage","url":"classes/gettextbuilder.html#setlanguage","classes":"tsd-kind-method tsd-parent-kind-class","parent":"GettextBuilder"},{"id":19,"kind":2048,"name":"detectLocale","url":"classes/gettextbuilder.html#detectlocale","classes":"tsd-kind-method tsd-parent-kind-class","parent":"GettextBuilder"},{"id":20,"kind":2048,"name":"addTranslation","url":"classes/gettextbuilder.html#addtranslation","classes":"tsd-kind-method tsd-parent-kind-class","parent":"GettextBuilder"},{"id":21,"kind":2048,"name":"build","url":"classes/gettextbuilder.html#build","classes":"tsd-kind-method tsd-parent-kind-class","parent":"GettextBuilder"},{"id":22,"kind":128,"name":"GettextWrapper","url":"classes/gettextwrapper.html","classes":"tsd-kind-class"},{"id":23,"kind":1024,"name":"gt","url":"classes/gettextwrapper.html#gt","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-private","parent":"GettextWrapper"},{"id":24,"kind":512,"name":"constructor","url":"classes/gettextwrapper.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class","parent":"GettextWrapper"},{"id":25,"kind":2048,"name":"subtitudePlaceholders","url":"classes/gettextwrapper.html#subtitudeplaceholders","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-private","parent":"GettextWrapper"},{"id":26,"kind":2048,"name":"gettext","url":"classes/gettextwrapper.html#gettext","classes":"tsd-kind-method tsd-parent-kind-class","parent":"GettextWrapper"},{"id":27,"kind":2048,"name":"ngettext","url":"classes/gettextwrapper.html#ngettext","classes":"tsd-kind-method tsd-parent-kind-class","parent":"GettextWrapper"},{"id":28,"kind":64,"name":"getGettextBuilder","url":"globals.html#getgettextbuilder","classes":"tsd-kind-function"}]}; |
{ | ||
"name": "@nextcloud/l10n", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "", | ||
@@ -9,3 +9,3 @@ "main": "dist/index.js", | ||
"build": "babel ./lib --out-dir dist --extensions '.ts,.tsx' --source-maps && tsc --emitDeclarationOnly", | ||
"build:doc": "typedoc --excludeNotExported --mode file --out dist/doc lib/index.ts && touch dist/doc/.nojekyll", | ||
"build:doc": "typedoc --excludeNotExported --mode file --out dist/doc lib && touch dist/doc/.nojekyll", | ||
"check-types": "tsc", | ||
@@ -27,15 +27,19 @@ "dev": "babel ./lib --out-dir dist --extensions '.ts,.tsx' --watch", | ||
"dependencies": { | ||
"core-js": "3.6.1" | ||
"core-js": "3.6.4", | ||
"node-gettext": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "7.7.7", | ||
"@babel/core": "7.7.7", | ||
"@babel/preset-env": "7.7.7", | ||
"@babel/preset-typescript": "7.7.7", | ||
"@babel/cli": "7.8.4", | ||
"@babel/core": "7.8.4", | ||
"@babel/preset-env": "7.8.4", | ||
"@babel/preset-typescript": "7.8.3", | ||
"@nextcloud/browserslist-config": "^1.0.0", | ||
"@nextcloud/typings": "^0.1.6", | ||
"babel-jest": "^24.9.0", | ||
"jest": "^24.9.0", | ||
"typedoc": "^0.15.6", | ||
"typescript": "3.7.4" | ||
"@types/node-gettext": "^2.0.1", | ||
"babel-jest": "^25.1.0", | ||
"babel-plugin-transform-class-properties": "^6.24.1", | ||
"gettext-parser": "^4.0.2", | ||
"jest": "^25.1.0", | ||
"typedoc": "^0.16.7", | ||
"typescript": "3.7.5" | ||
}, | ||
@@ -42,0 +46,0 @@ "browserslist": [ |
@@ -17,2 +17,6 @@ # @nextcloud/l10n | ||
### OC.L10n abstraction | ||
You can use helpers in this package in order generate code that also works when it's not loaded on a Nextcloud page. This is primary useful for testing. The logic will just return the original string if the global variable `OC` isn't found. | ||
In order to not break the l10n string extraction scripts, make sure to alias the imported function to match the legacy syntax: | ||
@@ -25,2 +29,45 @@ | ||
n('myapp', '%n cloud', '%n clouds', 100) | ||
``` | ||
``` | ||
See the [localization docs](https://docs.nextcloud.com/server/stable/developer_manual/app/view/l10n.html) for more info. | ||
### Independent translation | ||
You can use this package to translate your app or library independent of Nextcloud. For that you need .po(t) files. These can be extracted with [gettext-extractor](https://github.com/lukasgeiter/gettext-extractor). | ||
```js | ||
import { getGettextBuilder } from '@nextcloud/l10n/gettext' | ||
const lang = 'sv' | ||
const po = ... // Use https://github.com/smhg/gettext-parser to read and convert your .po(t) file | ||
const gt = getGettextBuilder() | ||
.detectLocale() | ||
.addTranslation('sv', po) | ||
.build() | ||
``` | ||
#### Translate single string | ||
```js | ||
gt.gettext('my source string') | ||
``` | ||
#### Placeholders | ||
```js | ||
gt.gettext('this is a {placeholder}. and this is {key2}', { | ||
placeholder: 'test', | ||
key2: 'also a test', | ||
}) | ||
``` | ||
See [the developer docs for general guidelines](https://docs.nextcloud.com/server/latest/developer_manual/app/view/l10n.html). | ||
#### Translate plurals | ||
```js | ||
gt.ngettext('%n Mississippi', '%n Mississippi', 3) | ||
``` | ||
See [the developer docs for general guidelines](https://docs.nextcloud.com/server/latest/developer_manual/app/view/l10n.html). |
@@ -5,2 +5,3 @@ { | ||
"module": "commonjs", | ||
"esModuleInterop": true, | ||
"declaration": true, | ||
@@ -7,0 +8,0 @@ "outDir": "./dist", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
454965
30
2537
72
2
13
+ Addednode-gettext@^2.0.0
+ Addedcore-js@3.6.4(transitive)
+ Addedlodash.get@4.4.2(transitive)
+ Addednode-gettext@2.1.0(transitive)
- Removedcore-js@3.6.1(transitive)
Updatedcore-js@3.6.4