Translate(localization) razor SPA
sample with custom css suppurt ar/en check source code to figure more extensions:
https://github.com/MhozaifaA/AppTranslate/tree/master/AppTranslate/Translate
Inject in Program.cs
using AppTranslate.Translate.Configure;
//....
builder.Services.AddAppTranslateClientSide(config=> config.Thesaurus( ("Hello" , "مرحبا") ) );
//.... or
await services.AddAppTranslateClientSide("thesaurus.json");
//....
in Component
@inject AppTranslate.Translate.IAppTranslate Translate
@implements IDisposable
<h1 class="arFlip-1 arAlign">@Translate["Hello"]</h1>
<button class="btn btn-primary" @onclick="ChangeLanguge">@Translate["..."]</button>
@code{
protected override void OnInitialized()
{
Translate.OnChange += StateHasChanged;
}
private void ChangeLanguge()
{
Translate.Switch();
}
public void Dispose()
{
Translate.OnChange -= StateHasChanged;
}
}
Inject in Startup.cs
using AppTranslate.Translate.Configure;
//....
services.AddAppTranslateServerSide(config => config.Thesaurus(("Hello", "مرحبا")));
//.... or
services.AddAppTranslateServerSide("thesaurus.json");
//....
in Component
@inject AppTranslate.Translate.IAppTranslate Translate
@implements IDisposable
<h1 class="arFlip-1 arAlign">@Translate["Hello"]</h1>
<button class="btn btn-primary" @onclick="ChangeLanguge">@Translate["..."]</button>
@code{
protected override void OnInitialized()
{
Translate.OnChange += StateHasChanged;
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
await Translate.Inject();
}
private void ChangeLanguge()
{
Translate.Switch();
}
public void Dispose()
{
Translate.OnChange -= StateHasChanged;
}
}
ChangeThesaurus(thesaurusPath,code?)
``enabled async``
Switch(code?)
SwitchToDefault(code?)
SwitchToUnDefault(code?)
Switch(thesaurusPath,code?)
``using only in server side``
Inject(key?)
``enabled async``
OnceSupportLTR()
OnceSupportRTL()
``properties``
IsDefault
Path
Code
IsSupportRTL
``state``
Action OnChange
- Enable multi languages in one file
- Stable async in WASM
- Support own influencing HTML head included inside AppTranslate
- Custome localization components
- Default Language code in URL app
- Storage localy files with reload
client side
https://github.com/MhozaifaA/AppTranslate/tree/master/BlazorApp
server side
https://github.com/MhozaifaA/AppTranslate/tree/master/BlazorAppServer