Umbraco 7 Working with languages/Dictionary

10,421

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")
Share:
10,421
Jonas m
Author by

Jonas m

Just a simple guy

Updated on June 14, 2022

Comments

  • Jonas m
    Jonas m almost 2 years

    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
    Jonas m about 9 years
    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?
  • Morten OC
    Morten OC about 9 years
    You could use GetDictionaryItemByKey our.umbraco.org/Documentation/Reference/Management-v6/Servic‌​es/… It will give you a list with iso codes for the selected item.
  • Jonas m
    Jonas m about 9 years
    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?
  • Morten OC
    Morten OC about 9 years
    @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.
  • Jonas m
    Jonas m about 9 years
    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: stackoverflow.com/questions/29509288/… - Thanks :)