Get Available Language Codes of current Node Tree ...
# help-with-umbraco
p
Is there a way to get the available language codes for the current node tree? This is what i got currently but it gives me all configured languages in the backoffice
Copy code
C#
    public bool DoesLanguageExist(string isoCode)
    {
        var languages = _localizationService.GetAllLanguages();
        return languages.Any(language => language.IsoCode == isoCode);
    }
}
a
I think you can check with the domainService to see what the configured domains for a node are, with ofcourse what languages are available
If you need to do it per node, for example for the rendering of a flag for each available culture its a bit more complex
Then you get something like
_allLanguages = localizationService.GetAllLanguages().ToList();
Then loop through each language, and check if the current node has a variant in that language
Copy code
var url = currentPage.Url(_publishedUrlProvider, language.IsoCode);
and if they do, add them to a object that contains all flagitems
d
If you're going to check on domains frequently, then maybe you want to use the domain cache inside an Umbraco context. That should save you a roundtrip to the database, as opposed to localization service or domain service.
p
Thanks alot to you guys! Helped me alot! @D_Inventor @Ambert
p
@User May I suggest “all” instead of "guys"? We use gender inclusive language in this Discord. 😀
44 Views