Image based on language

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 years ago
I would like some idea on how to integrate an image to the footer using the selected language. Example if English is selected i want to show an image in my theme folder (Themes\Test\Content\Images) ENTEST.png and if Spanish is selected i want to see ESTEST.png. Thank you
9 years ago
Only Javascript.
After changing Language combobox change css style (image link).
9 years ago
This is how i am doing it now, but i dont want to search for a Text, i rather look up the language ID instead. I am missing the correct code to use in MVC, i am a newby to MVC !

<div>
    @if (T("Account.MyAccount").Text == "My account")
    {
        <img src="@Url.Content("~/Themes/NicoleHouse/Content/images/footer/footerEN.jpg")" alt="" />
    }
    @if (T("Account.MyAccount").Text == "account.myaccount")
    {
        <img src="@Url.Content("~/Themes/NicoleHouse/Content/images/footer/footerES.jpg")" alt="" />
    }
</div>
Whats in bold is what does the trick looking up a specific text.

Thank you
9 years ago
OK Found what i really needed which was serch for a specific LANGUAGE ID used, reather then a TEXT used ! For any ones help here is the code.

@if (Model.WorkingLanguageId == 1 )
            {
                <img src="@Url.Content("~/Themes/NicoleHouse/Content/images/footer/footerEN.jpg")" alt="" />
                }


Change the 1 to any decired LANGUAGE ID...
9 years ago
I would better write it the following way:
@if (WorkContext.WorkingLanguage.UniqueSeoCode == "en")
{
}
9 years ago
Thank you will modify as you advised.
6 years ago
a.m. wrote:
I would better write it the following way:
@if (WorkContext.WorkingLanguage.UniqueSeoCode == "en")
{
}


Hi, I have a similar requirement but in 3.8.  If I follow this, in the view I get the compiler error of WorkContext not being in the current context.  I have tried referencing a few libraries, but not having any joy.  Can you help me apply this in 3.8 please?  

Steve.
6 years ago
OK, so some progress in the right direction hopefully.  I have added logic to the controller to be more correct.  This appears to work, but _workContext.WorkingLanguage.UniqueSeoCode is always Null.  Anyone any clues.

Steve.


using System.Web.Mvc;
using Nop.Core;
using Nop.Core.Caching;
using Nop.Services.Configuration;
using Nop.Services.Localization;
using Nop.Services.Media;
using Nop.Services.Stores;
using Nop.Web.Framework.Controllers;

namespace Nop.Plugin.Widgets.Step1Header.Controllers
{
    public class Step1HeaderController : BasePluginController
    {
        private readonly IWorkContext _workContext;
        private readonly IStoreContext _storeContext;
        private readonly IStoreService _storeService;
        private readonly IPictureService _pictureService;
        private readonly ISettingService _settingService;
        private readonly ICacheManager _cacheManager;
        private readonly ILocalizationService _localizationService;

        public Step1HeaderController(IWorkContext workContext,
            IStoreContext storeContext,
            IStoreService storeService,
            IPictureService pictureService,
            ISettingService settingService,
            ICacheManager cacheManager,
            ILocalizationService localizationService)
        {
            this._workContext = workContext;
            this._storeContext = storeContext;
            this._storeService = storeService;
            this._pictureService = pictureService;
            this._settingService = settingService;
            this._cacheManager = cacheManager;
            this._localizationService = localizationService;
        }

        [AdminAuthorize]
        [ChildActionOnly]
        public ActionResult Configure()
        {

            return View("~/Plugins/Widgets.Step1Header/Views/Step1Header/Configure.cshtml");
        }

        [ChildActionOnly]
        public ActionResult PublicInfo(string widgetZone, object additionalData = null)
        {
            
            ViewBag.Language = _workContext.WorkingLanguage.UniqueSeoCode;
            ViewBag.Language2 = _workContext.WorkingLanguage.Id;
            if (_workContext.WorkingLanguage.UniqueSeoCode == "en")
            {
                ViewBag.Language = "en";
            }
            return View("~/Plugins/Widgets.Step1Header/Views/Step1Header/PublicInfo.cshtml");
        }
    }
}
6 years ago
OK, got it working, because I was in a plugin.

I have changed IWorkContext to :

        private readonly IWorkContext _workContext = EngineContext.Current.Resolve<IWorkContext>();

removing the setting of the value below and then calling _WorkContext provides the correct value.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.