https://github.com/fable-compiler/fable.i18next
Fable bindings and helpers for [i18next](https://www.i18next.com/)
https://github.com/fable-compiler/fable.i18next
Last synced: 2 months ago
JSON representation
Fable bindings and helpers for [i18next](https://www.i18next.com/)
- Host: GitHub
- URL: https://github.com/fable-compiler/fable.i18next
- Owner: fable-compiler
- License: apache-2.0
- Created: 2021-07-25T18:36:15.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-09-27T16:46:07.000Z (over 2 years ago)
- Last Synced: 2025-04-04T16:41:56.102Z (3 months ago)
- Language: JavaScript
- Size: 8.2 MB
- Stars: 7
- Watchers: 5
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Fable.I18Next
Fable bindings and helpers for [i18next](https://www.i18next.com/). The bindings work with Fable and on .NET Core for ServerSide-Rendering.
Created by [@atheck](https://github.com/atheck).
## Installation
```
npm install --save i18next # or
yarn add i18nextpaket add Fable.I18Next --project [yourproject]
```## Usage
Make sure your Fable project .fsproj has the `FABLE_COMPILER` property set:
```xml
net5.0
FABLE_COMPILER
// ...
```
Create a `translations.json` file like the following:
```json
{
"de": {
"translation": {
"MyKey": "Das ist ein deutscher Text"
}
},
"en": {
"translation": {
"MyKey": "This is a english text"
}
}
}
```Hook in Fable.I18Next in your Elmish Program inside App.fs:
```fs
module Appopen Fable.Core.JsInterop
// ...
let resources : obj = import "*" "./translations.json"
promise {
do! I18n.Init(resources,"en")
Program.run program
}
|> Promise.start```
If you want to access the translation then just use:
```fs
open Fable.I18Next
I18n.Translate "MyKey"
```
If you want to switch the language then use the `I18n.ChangeLanguage`. If you use Elmish then you can put it into a Cmd:
```fs
open Fable.I18Next
let update msg model =
match msg with
// ...
| ChangeLanguage newLanguage ->
model, Cmd.OfPromise.either I18n.ChangeLanguage newLanguage LanguageChanged Error
// ...```
### Usage on .NET Core
```fs
let resourceFileName =
let app = System.Reflection.Assembly.GetExecutingAssembly().Location
let startupPath = System.IO.Path.GetDirectoryName app
Path.Combine(startupPath, "translations.json")I18n.Init(resourceFileName, initialLang)
```Please read the [i18next docs](https://www.i18next.com/) for more sophisticated examples.
## Release process
After installing dependencies with `yarn install`, run `yarn run build publish` to publish a new package