7

Our project has finally come to a point where we can add translations. I just cant seem to figure out how to actually work with languages in Umbraco 7. Ive added a language and a few dictionary items in the backend, but how do i select the givent language in my code?

Are there any helpers to get translations in the API? Like DictionaryHelper.Translate("Answers","da-DK"); ? Or similar? Is there a way to set the language, etc in the startup controller, and just always get that language from the dictionary?

Thanks in advance. Jonas.

Jonas m
  • 2,136
  • 3
  • 17
  • 37

1 Answers1

15

First, you have to create your languages under Settings > Languages.

Next step is to set the language on each node, or just on a top node. So lets say your content tree looks like this:"

enter image description here

Then right click on "da" and select "Culture and Hostnames". Select "da-DK" for this node. All subnodes (and "da" node) will now have the danish language.

So now its simple to get dictionary items in razor and c# code. In razor:

@Umbraco.GetDictionaryValue("Answers")
Morten OC
  • 1,754
  • 2
  • 23
  • 26
  • Thank you Morten. Lets assume that i do not have a node, but a static page with Angular to represent the frontend. How would i, programatically, set the language for the dictionary? – Jonas m Apr 07 '15 at 10:51
  • You could use _GetDictionaryItemByKey_ https://our.umbraco.org/Documentation/Reference/Management-v6/Services/LocalizationService It will give you a list with iso codes for the selected item. – Morten OC Apr 07 '15 at 11:28
  • Thank you Morten. As a last question, if you dont mind, i have a custom section where the tree should vary depending on the logged in users permissions, but since its stored in cached tree.config, it doesent apply changes unless i update the BIN folder. Do you know of any programatical way to clear the tree.config? – Jonas m Apr 08 '15 at 06:43
  • @Jonasm hm Im not sure this is the right way to do it. Tree.config should always be cached as long as possible. I think you should have the permission test a level deeper. So, all users share the same Section, and then you control permissions in that section. You will then hide/show the right nodes to the right user. – Morten OC Apr 08 '15 at 18:21
  • Hey Morten, Thank you for the answer. Actually, that is what i am trying to do. Would you mind having a look here, where i filed a stack with more details: http://stackoverflow.com/questions/29509288/refresh-sectiontree-on-new-user-login - Thanks :) – Jonas m Apr 10 '15 at 14:09