@samitouri / QOSami-HFS / commits / 27e7dcde

doc: plugins i18n

Massimo Melina committed Jan 28, 2024 at 15:06 UTC 27e7dcde58c14e87830b6b550dc8a28b5f2eac08
2 files changed +18 -1
README.md
+1
@@ -189,6 +189,7 @@ Some actions you can take for improved security:
189 - Appending `?overwrite` on uploads, will try override the dont_overwrite_uploading configuration, provided you also have delete permission
190 - Right-click on "check for updates" will let you input a URL of a version to install
191 - Admin: ctrl+digit will switch page
192 +- Appending ?overwrite to the URL of an upload request will overwrite existing file if you have delete permission
193
194 ## Contribute
195
dev-plugins.md
+17 -1
@@ -206,6 +206,7 @@ The HFS objects contains many properties:
206 - `h` shortcut for React.createElement
207 - `t` [translator function](https://github.com/rejetto/hfs/blob/main/frontend/src/i18n.ts)
208 - `_` [lodash library](https://lodash.com/docs/)
209 +- `navigate: (uri: string): void` use this if you have to change the page address without causing reload
210 - `emit: (name: string, params?: object) => any[]` use this to emit a custom event. Prefix name with your plugin name to avoid conflicts.
211 - `Icon: ReactComponent` Properties:
212 - `name: string` refer to file `icons.ts` for names, but you can also enter an emoji instead.
@@ -364,14 +365,29 @@ h('button', { onClick: () => console.log('hi') }, 'Say hi')
365
366 Where `h` is just `import { createElement as h } from 'react'`.
367
368 +## Internationalization (i18n)
369 +
370 +To make your plugin multi-language you can use `HFS.t` function in javascript, like this: `HFS.t("Hello!")`.
371 +Now, to add translations, you'll add files like `hfs-lang-XX.json` to your plugin (same folder as plugin.js),
372 +where XX is the language code. The system is basically the same used to translate the rest of HFS,
373 +and you can [read details here](https://github.com/rejetto/hfs/wiki/Translation).
374 +
375 +In the previous example "Hello!" is used both as key for translation and as for default text.
376 +If you want to separate these 2 things, just pass 2 parameters, key and default text. Eg: `HFS.t('greeting', "Hello!")`.
377 +
378 +If you need to pass variables in the text, introduce a third parameter in the middle.
379 +Eg: `HFS.t('filter_count', {n:filteredVariable}, "{n} filtered")`
380 +
381 ## API version history
382
383 - 8.65 (v0.51.0)
384 - plugin's own hfs-lang files
371 - - props.can_overwrite
385 + - HFS.state.props.can_overwrite
386 - ctx.state.considerAsGui
387 - new event: userPanelAfterInfo
388 - breaking: moved custom properties from ctx to ctx.state
389 + - HFS.navigate
390 + - internationalization
391 - 8.5 (v0.49.0)
392 - new event: entry
393 - exports.onDirEntry: entry.icon