How to add custom languages to the "add language" ...
# help-with-umbraco
w
I have an Umbraco 13 site that needs to include translations for languages that aren't currently included in the language dropdown when you go to add a language in the backoffice. How would I go about adding these languages in? So far I have tried creating a custom locale on my pc in hopes that the backoffice would pull from my locale list when I run my site locally, but I haven't had success there yet. Any and all help is appreciated! https://cdn.discordapp.com/attachments/1197660661275177092/1197660661837201479/language_issue.png?ex=65bc1369&is=65a99e69&hm=fd7668cc9d5a069ddc47b828632dfa999ed18867c0690b219d0a806db7e3012e&
j
You can create a language with your own isocode directly through the localizationservice. Fx like this:
Copy code
csharp
var lang = new Language("da-GB", "Danish (Great Britain)");
_localizationService.Save(lang);
Results in https://cdn.discordapp.com/attachments/1197660661275177092/1197827043166007336/image.png?ex=65bcae5d&is=65aa395d&hm=e540b9213feacc653b1eb8ee3e1a1ac3d0ea191777bdfe82e5480456446edbd5&
w
much appreciated!
d
@warlloch Hey, currently doing something similar. Where did you include the code in your project?
Alternatively @Jemayn, since you provided this solution, maybe you know the answer to this? I know we've discussed something similar in the past. Where did you place it for this specific example? 🙂
j
I just placed it in an API Controller for quick testing. For a multienvironment site running this I would add it in a UmbracoApplicationStartedNotification which runs only on site startup: https://docs.umbraco.com/umbraco-cms/reference/notifications/umbracoapplicationlifetime-notifications Then do a quick check via the localization service to see if it exists (https://github.com/umbraco/Umbraco-CMS/blob/contrib/src/Umbraco.Core/Services/ILocalizationService.cs#L137), if not add it.
d
Great, thank you so much!
w
I did the same thing 👍🏼 @dalle3430
d
Thanks guys, works like a charm. Just a quick question, is it expected that the language is automatically added to the website's languages and not to the dropdown of language options to choose from?
p
@User May I suggest “Umbracians” instead of "guys"? We use gender inclusive language in this Discord. 😀
j
It looks the same for me. I think the dropdown is just based on the machines known cultures, and this is a workaround to add specific ones directly to Umbraco (they are then stored in the databases language table)'
d
Ok, thanks!
109 Views