Localised title using TreeAttribute for custom TreeController in custom Section
Hi all,
I have create a custom section (Umbraco v7.4) and use a custom TreeController providing only one menu item (Import); no child nodes.
Code looks like this:
[PluginController("umbCustomSection")]
[Umbraco.Web.Trees.Tree("umbCustomSection", "umbProductsExtensionTree", "Products", iconClosed: "icon-doc")]
public class UmdProductsTreeController : TreeController
{...}
This results in a custom section with a root node titled "Products" (=the 3rd parameter of the TreeAttribute used in the above code).
How can this title be localised, such that when I change my language, this title will show the translated text (eg. "Producten" for nl-NL )?
Thanks for your answer.
I am not sure how I would get this to work in my case.
Your example looks quite a lot like mine including the usage of the language files.
One remarkable difference is that your first parameter (appAlias) and second parameter (alias) are exactly the same.
Maybe that's the trick to get both section and treenode translated?
In my case, my section and treecontroller are named differently. So, I get a neat translation for the section, but the root node is not translated and will named Products (the 3rd parameter) for all languages I choose.
Any special things I need to pay attention to get this working in my situation?
Meanwhile I have setup and run Formulate on my machine ... out of curiousity (interesting stuff!) and to see how your code works with regards to translating the specific text.
Unfortunately, it really looks like you have the same need I have...
... That is, the FORMULATE text that is shown above the nodes
Forms,
Layouts,
Data Source,
Data Values,
Validation Library
is not translated.
In Spanish for example, it will remain FORMULATE and will not be translated to FORMULATE (ES) as defined in your es-ES.xml.
I will search further (and hopefully receive some new thoughts from the community) on this.
Guess that a solution might be interesting for you as well ;-)
Localised title using TreeAttribute for custom TreeController in custom Section
Hi all,
I have create a custom section (Umbraco v7.4) and use a custom TreeController providing only one menu item (Import); no child nodes. Code looks like this:
This results in a custom section with a root node titled "Products" (=the 3rd parameter of the TreeAttribute used in the above code).
How can this title be localised, such that when I change my language, this title will show the translated text (eg. "Producten" for nl-NL )?
I did that in Formulate. I have a tree controller much like your own: https://github.com/rhythmagency/formulate/blob/b4145be9c54b8b8dad0e73de59d10ec6633e6dd5/src/formulate.app/Trees/FormulateTreeController.cs#L33
All I have to do is add a language file that contains the translation: https://github.com/rhythmagency/formulate/blob/b4145be9c54b8b8dad0e73de59d10ec6633e6dd5/src/formulate.app/App_Plugins/formulate/Lang/en-GB.xml
Note that this will only work for new versions of Umbraco. You can find details here: https://our.umbraco.org/Documentation/Extending/Language-Files/Language-Files-For-Packages/
Hi Nicholas,
Thanks for your answer. I am not sure how I would get this to work in my case. Your example looks quite a lot like mine including the usage of the language files. One remarkable difference is that your first parameter (appAlias) and second parameter (alias) are exactly the same.
Maybe that's the trick to get both section and treenode translated?
In my case, my section and treecontroller are named differently. So, I get a neat translation for the section, but the root node is not translated and will named Products (the 3rd parameter) for all languages I choose.
Any special things I need to pay attention to get this working in my situation?
I've actually just begun to add localization support for the tree nodes for Formulate in my most recent commit on the develop branch: https://github.com/rhythmagency/formulate/commit/80f146efa703ca3e8588eb802074fadcd6decf0a
As you can see, I create multiple root nodes, and the only way I could get that working was to "manually" create them: https://github.com/rhythmagency/formulate/blob/80f146efa703ca3e8588eb802074fadcd6decf0a/src/formulate.app/Trees/FormulateTreeController.cs#L217
That looks like this:
That has "Validation Nodes" (from the above code snippet).
You can see there I'm calling my helper function,
LocalizationHelper.GetTreeName
to get the translated version of the tree node.However, in your instance, if you want to avoid doing that, maybe there is a better way. I note that the code language files contain this section:
Perhaps if you add a key to the
treeHeaders
area, Umbraco will know how to translate it?Hi Nicholas,
Appreciate your input very much!
Meanwhile I have setup and run Formulate on my machine ... out of curiousity (interesting stuff!) and to see how your code works with regards to translating the specific text.
Unfortunately, it really looks like you have the same need I have...
... That is, the FORMULATE text that is shown above the nodes
is not translated.
In Spanish for example, it will remain FORMULATE and will not be translated to FORMULATE (ES) as defined in your es-ES.xml.
I will search further (and hopefully receive some new thoughts from the community) on this.
Guess that a solution might be interesting for you as well ;-)
Yes, I have found the solution with help from Nicholas!
Part of the solution is Nicholas' comment about adding a key to the treeHeaders area.
So first make sure to add a key (with alias = name of the Custom TreeController; umbProductsExtensionTree in my case) to the translation files.
For example, in en-US.xml :
This is part one of the solution.
Next, make sure that the provided title text in the TreeAttribute above the custom TreeController is empty!
Otherwise it will not be translated!
Example:
These two changes finally gave me the translated text instead of the hardcoded text.
Hopefully the Umbraco team will document this rather "hidden" feauture.
Yeah, getting trees up and running is a PITA.
Glad to hear you got it all sorted. Perhaps I'll integrate some of what you've learned into Formulate :-)
Worked for me! https://github.com/rhythmagency/formulate/commit/08eef0bbee2a54a3923a204bf8b11c30caa4b4b8
I've just registered to say thank you !
is working on a reply...