Hi,
I have a requirement to get localized strings on specific languages. In my MVC application, this is achieved successfully by using the following:
var cultureInfo = new CultureInfo(languageName, true);
var str = LocalizationHelper.GetString(IppexCloudConsts.LocalizationSourceName, "AboutUs", cultureInfo);
I now have the same requirment within an Azure Function. I have set this up to run ABP. However, the code above now simply returns the label rather than the localized string. Without the culture info parameter, I am still getting localized values (using the default culture within which the function is running).
ABP is bootstrapped into the function using the following code:
public static class Bootstrapper
{
private static bool IsStarted = false;
private static readonly object _syncLock = new object();
public static AbpBootstrapper AbpBootstrapper { get; private set; }
public static void Startup()
{
if (!IsStarted)
{
lock (_syncLock)
{
if (!IsStarted)
{
var bootstrapper = AbpBootstrapper.Create<IppexCloudAzureFunctionsModule>();
bootstrapper.Initialize();
AbpBootstrapper = bootstrapper;
IsStarted = true;
}
}
}
}
}
My module code is as follows:
[DependsOn(typeof(IppexCloudDataModule), typeof(IppexCloudUploadApplicationModule), typeof(IppexCloudAzureFileStorageModule))]
public class IppexCloudAzureFunctionsModule : AbpModule
{
public override void PreInitialize()
{
Database.SetInitializer<IppexCloudDbContext>(null);
}
public override void Initialize()
{
IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
}
}
8 Answer(s)
-
0
Hi @philwynn
Normally localization source is *LocalizationConfigurer.Configure method in the PreInitialize of your app's CoreModule.
Could you check if your Core module's PreInitialize method is executed or not ?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi,
Yes, it is being executed.
I have since found, that if I use an instance of LocalizationManager rather than the static LocalizationHelper method, I do get the correct localized string back.
I would, however, appreciate a solution for LocalizationHelper, as using an instance will cause me much refactoring.
Many thanks
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi, you can easily get the
instanceof localization manager under abp service/controller when developing MVC application.However, if you really need to accees it via static methods, you can try using
IocManager.Instance()to resolve the localization manager instance (though it is not recommended)Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
I am running this code within the context of an Azure Function, so do not have access to anything MVC related.
Do you have any idea as to why LocalizationHelper is not working as described?
You say that it is not recommended to use IocManager.Instance(). Could you explain why this is please?
Many thanks.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
I am wondering if the language used by LocalizationHelper gets set when I initialize the AbpBootstrapper.
If this is the case, how can I programmatically change this language setting?
If I can do this, then I won't need to pass in the culture info to get the correct string (this would be ok, as each invocation of an Azure Funtion runs its own thread)
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
You say that it is not recommended to use IocManager.Instance(). Could you explain why this is please?
It was under the assumption that you are using
IocManager.Instance()in your application code.However, it seems that you want to access localization source from azure function. Currently there is no such built-in functionality.
You need to share the code for
LocalizationHelper.cs.Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
LocalizationHelper is an Abp class:
Abp.Localization.LocalizationHelper
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi, you can try debug the dictionaries in the
LocalizationManagere.g refering to the method in
Abp.Localization.LocalizationHelperLocalizationManager.Value.GetSource(sourceName).DictionaryProvider.Dictionaries.ValuesMarkdown is supportedCopy & paste or drag & drop images (max 30 MB per image)