Skip to content

Commit

Permalink
doc: plugins i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
rejetto committed Jan 28, 2024
1 parent 6bd3f2f commit 27e7dcd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ Some actions you can take for improved security:
- Appending `?overwrite` on uploads, will try override the dont_overwrite_uploading configuration, provided you also have delete permission
- Right-click on "check for updates" will let you input a URL of a version to install
- Admin: ctrl+digit will switch page
- Appending ?overwrite to the URL of an upload request will overwrite existing file if you have delete permission

## Contribute

Expand Down
18 changes: 17 additions & 1 deletion dev-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ The HFS objects contains many properties:
- `h` shortcut for React.createElement
- `t` [translator function](https://github.com/rejetto/hfs/blob/main/frontend/src/i18n.ts)
- `_` [lodash library](https://lodash.com/docs/)
- `navigate: (uri: string): void` use this if you have to change the page address without causing reload
- `emit: (name: string, params?: object) => any[]` use this to emit a custom event. Prefix name with your plugin name to avoid conflicts.
- `Icon: ReactComponent` Properties:
- `name: string` refer to file `icons.ts` for names, but you can also enter an emoji instead.
Expand Down Expand Up @@ -364,14 +365,29 @@ h('button', { onClick: () => console.log('hi') }, 'Say hi')

Where `h` is just `import { createElement as h } from 'react'`.

## Internationalization (i18n)

To make your plugin multi-language you can use `HFS.t` function in javascript, like this: `HFS.t("Hello!")`.
Now, to add translations, you'll add files like `hfs-lang-XX.json` to your plugin (same folder as plugin.js),
where XX is the language code. The system is basically the same used to translate the rest of HFS,
and you can [read details here](https://github.com/rejetto/hfs/wiki/Translation).

In the previous example "Hello!" is used both as key for translation and as for default text.
If you want to separate these 2 things, just pass 2 parameters, key and default text. Eg: `HFS.t('greeting', "Hello!")`.

If you need to pass variables in the text, introduce a third parameter in the middle.
Eg: `HFS.t('filter_count', {n:filteredVariable}, "{n} filtered")`

## API version history

- 8.65 (v0.51.0)
- plugin's own hfs-lang files
- props.can_overwrite
- HFS.state.props.can_overwrite
- ctx.state.considerAsGui
- new event: userPanelAfterInfo
- breaking: moved custom properties from ctx to ctx.state
- HFS.navigate
- internationalization
- 8.5 (v0.49.0)
- new event: entry
- exports.onDirEntry: entry.icon
Expand Down

0 comments on commit 27e7dcd

Please sign in to comment.