Localized Title in Dynamic generated Topic (2.65)

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
Hello,

i have made some changes in the Menu to dynamically display Topics but i'm having trouble displaying the localized string value of the Topic ...

My code is the following:

@foreach (var topic in topicService.GetAllTopics())
    {
      
            if (topic.TypeId.Equals("Area"))
            {
            <li>
            <a href="@Url.RouteUrl("Topic", new { SystemName = topic.SystemName })">@(topic.Title)</a>
            </li>
            }
    }

The value that i'm getting from the @(topic.Title) is the standard one and not the localized one :(

Could someone help me on this?

Thanks in advanced ;)
11 years ago
you have to use ILocalizationService to get localize your string.

and use like

_localizationService.GetResource(topic.Title, lang.Id)
11 years ago
Thanks for the quick response elaa1979 :)

I made the change that you suggested but it did not resolved the problem :(

@{
    var topicService =  Nop.Core.Infrastructure.EngineContext.Current.Resolve<ITopicService>();
    var localizeService = Nop.Core.Infrastructure.EngineContext.Current.Resolve<ILocalizationService>();
    var currentContext = Nop.Core.Infrastructure.EngineContext.Current.Resolve<IWorkContext>();
}

    @foreach (var topic in topicService.GetAllTopics())
    {
    
            if (topic.TypeId.Equals("Area"))
            {
            <li>
            <a href="@Url.RouteUrl("Topic", new { SystemName = topic.SystemName })">@localizeService.GetResource(topic.Title, currentContext.WorkingLanguage.Id)</a>
            </li>
            }

    }

Do you see any problem in this code (the currentContext.WorkingLanguage.Id is returning the correct ids)?

Thanks for the help
11 years ago
Problem solved :)

@using Nop.Services.Topics;
@using Nop.Services.Localization;
@using Nop.Core;

@{
    var topicService =  Nop.Core.Infrastructure.EngineContext.Current.Resolve<ITopicService>();
    var localizeService = Nop.Core.Infrastructure.EngineContext.Current.Resolve<ILocalizationService>();
    var currentContext = Nop.Core.Infrastructure.EngineContext.Current.Resolve<IWorkContext>();
}

   @foreach (var topic in topicService.GetAllTopics())
    {
            <li>
            <a href="@Url.RouteUrl("Topic", new { SystemName = topic.SystemName })">@topic.GetLocalized(x=>x.Title,currentContext.WorkingLanguage.Id)</a>
            </li>
        }
    }

Thanks
11 years ago
Did you try just using @T ?

  @T(topic.Title)
11 years ago
Hi,

yes i did but with no luck :(
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.