Base solution for your next web application
Open Closed

Cant Add new Localization Source #2145


User avatar
0
benjaminrivero created

Hi All, i am trying to add another Localization Source

Using this code in my PROYECTNAMECoreModule.cs :

Configuration.Localization.Sources.Add(
                new DictionaryBasedLocalizationSource(
                    "DirectorioSource",
                    new XmlEmbeddedFileLocalizationDictionaryProvider(
                        Assembly.GetExecutingAssembly(),
                        "PROYECTNAME.Localization.DirectorioSource"
                        )
                    )
                );

Then, inside Core project, Localization folder, add a new Folder called "DirectorioSource" where inside I have just 1 XML called: DirectorioSource.xml (this file is marked as embedded resource)

The XML is simple:

<?xml version="1.0" encoding="utf-8" ?>
<localizationDictionary culture="en">
  <texts>
    <text name="Directorio" value="Directorio" />    
  </texts>
</localizationDictionary>

And finally on my code I use:

PROYECTNAMENavigationProvider.cs

AddItem(
                    new MenuItemDefinition(
                        "Directorio",
                        new LocalizableString("Directorio", "DirectorioSource"),
                        url: "#/directorio",
                        icon: "fa fa-phone"
                        )
                )

also try:

AddItem(
                    new MenuItemDefinition(
                        "Directorio",
                        new L("Directorio"),
                        url: "#/directorio",
                        icon: "fa fa-phone"
                        )
                )

At the end the Word Directorio appears like [Directorio] :roll:

What I am doing Wrong??

Thanks


4 Answer(s)
  • User Avatar
    0
    benjaminrivero created

    OK, I found that the problem was the XML, I change this just for testing:

    <?xml version="1.0" encoding="utf-8" ?>
    <localizationDictionary culture="en">
      <texts>
        <text name="Directorio" value="Directoriooooooo" />    
      </texts>
    </localizationDictionary>
    

    And in the menu the Word "Directoriooooo" appears, if I use the next code on the file PROYECTNAMENavigationProvider.cs:

    AddItem(
                        new MenuItemDefinition(
                            "Directorio",
                            new LocalizableString("Directorio", "DirectorioSource"),
                            url: "#/directorio",
                            icon: "fa fa-phone"
                            )
                    )
    

    Now the problem is on my razor view, where I am trying to show the word with this code:

    @L("Directorio")
    

    But this show [Directorio] again.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Thanks for sharing your solution. @L method uses default localization source, you can create a similar shortcut method in your ViewBase class.

    You can check the definition of @L here <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/f10fa5205c780bcc27adfe38aaae631f412eb7df/src/Abp.Web.Mvc/Web/Mvc/Views/AbpWebViewPageOfTModel.cs#L70">https://github.com/aspnetboilerplate/as ... del.cs#L70</a>

  • User Avatar
    0
    benjaminrivero created

    I was checking that file and on the line (115, check the link):

    <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/f10fa5205c780bcc27adfe38aaae631f412eb7df/src/Abp.Web.Mvc/Web/Mvc/Views/AbpWebViewPageOfTModel.cs#L115">https://github.com/aspnetboilerplate/as ... el.cs#L115</a>

    Is defined the method Ls. This method: "Gets localized string from given source for given key name..." so, is already done!!!

    On the Razor views can be called like this:

    <span>@Ls("SOURCENAME", "NameToShow")</span>

    And this will show the value for the key name (2 parameter) of the Localization Source passed (1 parameter)

    :mrgreen: :mrgreen: :mrgreen:

  • User Avatar
    0
    ismcagdas created
    Support Team

    Yes you are right, I was also sure that there was a @Ls method but somehow I couldn't find it yesterday :).