--- title: C#/SMAPI API tags: project-fluent --- # C#/SMAPI API Project Fluent's C#/SMAPI API allows modders to: * Use Fluent translations in their code. * Register custom Fluent functions that can be used when processing Fluent translations. ## Access the API You can access the API via SMAPI's `ModRegistry`: ```csharp var api = this.Helper.ModRegistry.GetApi<IFluentApi>("Shockah.ProjectFluent"); ``` You can grab the API interface [from the Github repository](https://github.com/Shockah/Stardew-Valley-Mods/tree/master/ProjectFluent/PublicAPI). ## Switching from i18n to Fluent translations To switch from i18n to Fluent translations, retrieve an `IFluent<string>` instance from the API: ```csharp // assuming you have an `IFluent<string> Fluent` property this.Fluent = api.GetLocalizationsForCurrentLocale(this.ModManifest); // alternatively, loading a subfile (`core.<locale>.ftl` instead of `<locale>.ftl`): this.Fluent = api.GetLocalizationsForCurrentLocale(this.ModManifest, "core"); ``` Now, you can switch from using i18n-based translations to Fluent: ```csharp // old code: string myTranslation = this.Helper.Translation.Get("translation-key"); // new code: string myTranslation = this.Fluent.Get("translation-key"); // alternatively: string myTranslation = this.Fluent["translation-key"]; ``` Just like with the i18n-based translations, you can provide an object that will provide values for translation tokens: ```csharp string myTranslation = this.Fluent.Get("translation-key", new { DaysLeft = 10 }); ```