Base solution for your next web application
Open Closed

check current language #3152


User avatar
0
avanekar02 created

hello

how can i check what is the current language from AppService in Application project and also how to check the language fro frontend controllers .

Thanks Anwar


10 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can use Thread.CurrentThread.CurrentUICulture.

    Thanks.

  • User Avatar
    0
    tteoh created

    <cite>ismcagdas: </cite> Hi,

    You can use Thread.CurrentThread.CurrentUICulture.

    Thanks.

    Hi Support,

    The above is only checking the language of current run-time right?

    What about User's current language saved in AbpSettings?

    I realized that each time the user select a language other than the system default language, the setting is saved into AbpSettings. However, this setting is NOT loaded and set the UI accordingly, right? (AngularJS template)

    Thanks, /tommy

  • User Avatar
    0
    tteoh created

    <cite>tteoh: </cite>

    <cite>ismcagdas: </cite> Hi,

    You can use Thread.CurrentThread.CurrentUICulture.

    Thanks.

    Hi Support,

    The above is only checking the language of current run-time right?

    What about User's current language saved in AbpSettings?

    I realized that each time the user select a language other than the system default language, the setting is saved into AbpSettings. However, this setting is NOT loaded and set the UI accordingly, right? (AngularJS template)

    Thanks, /tommy

    Hi Support,

    I found this: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/2103#thread-subscription-status">https://github.com/aspnetboilerplate/as ... ion-status</a>

    Any chance of releasing a patch? Need it for my current project. Thanks.

    /tommy

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    It is in our next release v2.1 and I hope it will be out soon probaly in two weeks. Is that ok for you ?

  • User Avatar
    0
    tteoh created

    <cite>ismcagdas: </cite> Hi,

    It is in our next release v2.1 and I hope it will be out soon probaly in two weeks. Is that ok for you ?

    Dear Support,

    I would really if you shed light on how the "abp" javascript object is being set during the application startup processing. Especially abp.js, I realized this is where abp.localization properties are set pertaining to languages.

    1. I just couldn't figure out for example, abp.localization.currentLanguage is set. Please kindly advice.

    2. I gathered there is corresponding typescript file, does it have any impact on how these abp is being set?

    3. I realized there are multiple locations that have localization impacts:

    • layout.cshtml (moment, angular, bootstrap, jquery)
    • appSetting.js (i18nServices)

    Originally, I was thinking to retrieve User Default Language in appSetting.js and then update header.js (vm.currentLanguage) with newly fetched language setting. Now, it seems there are so many factors to consider.

    Lastly, it will be great to add in a new control field (Disable) to AbpLanguages table, which will be used to construct the language list being assigned to abp.localization.languages. This way, it will help to control the language selection in both login screen and dropdown.

    This is how productive I had been for the day :oops:

    Yes. I look forward to the new release in two weeks.

    Thanks. /Tommy

  • User Avatar
    0
    bilalhaidar created

    Hi Tommy,

    Have a look at the following class, it is where the Current Language is being sent to client-side.

    <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.Web.Common/Web/Localization/LocalizationScriptManager.cs">https://github.com/aspnetboilerplate/as ... Manager.cs</a>

    Then, Abp Framework, on each new Http Request it runs this code:

    /// <summary>
            /// This method is called by ASP.NET system when a request starts.
            /// </summary>
            protected virtual void Application_BeginRequest(object sender, EventArgs e)
            {
                SetCurrentCulture();
            }
    
            protected virtual void SetCurrentCulture()
            {
                AbpBootstrapper.IocManager.Using<ICurrentCultureSetter>(cultureSetter => cultureSetter.SetCurrentCulture(Context));
            }
    

    Hence, once the user changes culture/language, the Cookie is changed on the client side + on every new request, that cookie is read and stored inside the :

    Thread.CurrentThread.CurrentCulture = new CultureInfo(language);
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);
    

    That's how I understand it.

    Hopefully, Ismail would comment more given his knowledge and experience in this framework.

    Regards

  • User Avatar
    0
    tteoh created

    <cite>drcgreece: </cite> Hi Tommy,

    Have a look at the following class, it is where the Current Language is being sent to client-side.

    <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.Web.Common/Web/Localization/LocalizationScriptManager.cs">https://github.com/aspnetboilerplate/as ... Manager.cs</a>

    Then, Abp Framework, on each new Http Request it runs this code:

    /// <summary>
           /// This method is called by ASP.NET system when a request starts.
           /// </summary>
           protected virtual void Application_BeginRequest(object sender, EventArgs e)
           {
               SetCurrentCulture();
           }
    
           protected virtual void SetCurrentCulture()
           {
               AbpBootstrapper.IocManager.Using<ICurrentCultureSetter>(cultureSetter => cultureSetter.SetCurrentCulture(Context));
           }
    

    Hence, once the user changes culture/language, the Cookie is changed on the client side + on every new request, that cookie is read and stored inside the :

    Thread.CurrentThread.CurrentCulture = new CultureInfo(language);
               Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);
    

    That's how I understand it.

    Hopefully, Ismail would comment more given his knowledge and experience in this framework.

    Regards

    Thank you for pointing out the class that does the "trick". :D

    Do you know specifically where the GetScript is being called at client side?

    I can't understand the second part on how the Thread at client side is set the latest language selection by users.

    Hope you are able to explain more...

    Thanks, /tommy

  • User Avatar
    0
    bilalhaidar created

    Look at the layout.cshtml under App\common\views\layout folder.

    Inside the layout.cshtml you have the following calls:

    
        <script src="~/api/AbpServiceProxies/GetAll?type=angular&v=@(Clock.Now.Ticks)"></script>
        <script src="~/api/AbpServiceProxies/GetAll?v=@(Clock.Now.Ticks)"></script>
        <script src="~/AbpScripts/GetScripts?v=@(Clock.Now.Ticks)" type="text/javascript"></script>
    

    Whenever you change language, a new request is set to sever and hence Application_BeginRequest runs to set the Thread culture.

    Hope this helps, Bilal

  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks @drcgreece :).

  • User Avatar
    0
    bilalhaidar created

    Most welcome and its our duty all of us to help each other here.