GithubHelp home page GithubHelp logo

mhozaifaa / apptranslate Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 1.56 MB

Translate(localization) razor SPA

C# 52.37% HTML 31.98% CSS 15.65%
blazor razor-spa localization blazor-client blazor-webassembly blazor-server without-js web-framework-application dotnet net5

apptranslate's Introduction

AppTranslate

Translate(localization) razor SPA

sample with custom css suppurt ar/en

Get started

Blazor Client-Side

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;
    }
}
   

Blazor Server-Side

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;
    }
    
   
}
   

Functionality

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

What features in future!

  • 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

Samples

client side https://github.com/MhozaifaA/AppTranslate/tree/master/BlazorApp
server side https://github.com/MhozaifaA/AppTranslate/tree/master/BlazorAppServer

apptranslate's People

Contributors

mhozaifaa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.