简体   繁体   English

如何在nopCommerce 3.9中获取语言文化的语言ID?

[英]How to get language ID for a language culture in nopCommerce 3.9?

Working with nopCommerce 3.9 how can find out the LanguageId (the ID stored in the nopCommerce DataBase) for a language if I only know the language culture? 如果我仅了解语言文化,如何使用nopCommerce 3.9如何找到一种语言的LanguageId(存储在nopCommerce数据库中的ID)?

For instance, when I want to add a locale resource in the Install() method of my plugin, I can achieve that by specifying the culture as string value 例如,当我想在插件的Install()方法中添加语言环境资源时,可以通过将区域性指定为字符串值来实现

this.AddOrUpdatePluginLocaleResource("Plugins.Payment.CheckMoneyOrder.AdditionalFee",
     "Additional fee", "en-US");

But other methods require the language ID and don't accept a culture string. 但是其他方法需要语言ID,并且不接受文化字符串。 (eg the SaveLocalizedSetting extension method for settings) (例如,设置的SaveLocalizedSetting扩展方法)

checkMoneyOrderPaymentSettings.SaveLocalizedSetting(x => x.DescriptionText,
                    languageId, //how to find out the ID for "en-US"
                    "my localized text");

How can I get the ID for "en-US" if I only know the locale resource at that point of execution? 如果我只知道执行时的语言环境资源,如何获得“ en-US”的ID?

You can try bellow code. 您可以尝试以下代码。 Add reference Nop.Services at your plugin. 在您的插件上添加参考Nop.Services。

var langId = _languageService.GetAllLanguages().Where(x => x.LanguageCulture == "en-US").FirstOrDefault().Id;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM