Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • David Zweben 268 posts 754 karma points
    Feb 19, 2020 @ 14:36
    David Zweben
    0

    Get all configured cultures in C#? (Umbraco 8)

    I'm trying to implement some language-related customizations, for which I need to get one of the following from C# inside a ContentFinder:

    Preferred: a list of the languages/cultures configured for the site in Settings

    Fallback: a list of all the languages/cultures available in Umbraco

    I know I can get the allowed cultures from a root content node, but I want to avoid the overhead of querying a specific node, as the code is going to be called on every page request.

    If anyone could point me in the right direction, it would be a big help.

    Thanks.

  • Kevin Jump 2348 posts 14896 karma points MVP 8x c-trib
    Feb 19, 2020 @ 14:40
    Kevin Jump
    100

    Hi David,

    The Localization service will return all installed languages

    localizationService.GetAllLanguages();
    

    It is a back office service so you might want to cache the results if you hitting it a lot.

  • David Zweben 268 posts 754 karma points
    Feb 19, 2020 @ 14:46
    David Zweben
    0

    Kevin,

    Perfect, this is exactly what I needed!

    I probably will need to cache this result. Can you tell me what method you would suggest to perform the caching? This is inside an Umbraco ContentFinder.

  • Kevin Jump 2348 posts 14896 karma points MVP 8x c-trib
    Feb 19, 2020 @ 14:50
    Kevin Jump
    1

    Hi

    I would lean towards using the AppCache.RuntimeCache

    (good small example here https://our.umbraco.com/Documentation/Reference/Cache/examples/tags#tagservice)

    And probibly something that clears it on the LocalizationService.DeletedLanguage or LocalizationService.SavedLanguage event just to be safe.

  • David Zweben 268 posts 754 karma points
    Feb 19, 2020 @ 14:52
    David Zweben
    0

    Perfect, thanks again!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies