Copied to clipboard

Flag this post as spam?

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


  • Jesse Andrews 162 posts 639 karma points
    Jun 21, 2019 @ 01:05
    Jesse Andrews
    0

    How do I access the settings defined in the config section within a custom ITranslationProvider?

    I'm working on a custom integration for a translation service a client uses, but I'm unsure how to access the settings set during configuration inside the custom TranslationProvider. I did notice a ProviderProperties field on the TranslationJob object, which I assume includes this information, but this object isn't available in the Active method. I want to flag it as active if it has an api key set in its settings. Is this possible?

    While I can get around this by adding the api key in app settings, I would like to manage all of the configuration in a single place that an umbraco user can easily access.

  • Kevin Jump 1896 posts 11907 karma points MVP 4x c-trib
    Jun 21, 2019 @ 10:17
    Kevin Jump
    100

    Hi Jesse,

    There are helper methods that allow you to get to the provider settings in the translations.config file.

    so within the provider, this would get the value for 'apiKey'

    _apiKey = TranslateConfigHelper.GetProviderSetting(this.Alias, "apiKey");
    

    there is also a generic version GetProviderSetting<TValue>(string providerName, string key, TValue defaultValue) which will let you get the value by type, e.g.

    int throttle = TranslateConfigHelper.GetProviderSetting(this.Alias, "throttle", 100);
    

    Also worth noting that if you store these values within the class, then you should load them in the Reload method, this is called by translation Manager when a user saves settings via the UI,

  • Jesse Andrews 162 posts 639 karma points
    Jun 21, 2019 @ 17:48
    Jesse Andrews
    0

    Thanks for the quick response Kevin.

Please Sign in or register to post replies

Write your reply to:

Draft