Umbraco 7 Working with languages/Dictionary
Asked Answered
E

1

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.

Euridice answered 7/4, 2015 at 9:54 Comment(0)
D
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")
Demarche answered 7/4, 2015 at 10:12 Comment(5)
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?Euridice
You could use GetDictionaryItemByKey our.umbraco.org/Documentation/Reference/Management-v6/Services/… It will give you a list with iso codes for the selected item.Demarche
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?Euridice
@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.Demarche
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: #29509788 - Thanks :)Euridice

© 2022 - 2024 — McMap. All rights reserved.