public static async Task SetLanguageAsync(long id, string language) { using (var context = new MikiContext()) { ChannelLanguage lang = await context.Languages.FindAsync(id); Locale locale = new Locale(id); if (LocaleNames.TryGetValue(language, out string val)) { language = val; } if (lang == null) { lang = context.Languages.Add(new ChannelLanguage() { EntityId = id, Language = language }).Entity; } lang.Language = language; cache.AddOrUpdate(id, lang.Language, (x, y) => lang.Language); await context.SaveChangesAsync(); } }
public async Task SetLocale(EventContext e) { using (var context = new MikiContext()) { ChannelLanguage language = await context.Languages.FindAsync(e.Guild.Id.ToDbLong()); Locale locale = Locale.GetEntity(e.Guild.Id.ToDbLong()); if (!Locale.Locales.ContainsKey(e.arguments.ToLower())) { await e.Channel.SendMessage(Utils.ErrorEmbed(locale, "{0} is not a valid language. use `>help setlocale` to see all of the memes xd")); return; } if (language == null) { language = context.Languages.Add(new ChannelLanguage() { EntityId = e.Guild.Id.ToDbLong(), Language = e.arguments.ToLower() }); } language.Language = e.arguments.ToLower(); await e.Channel.SendMessage(Utils.SuccessEmbed(locale, "Set locale to `{0}`\n\n**WARNING:** this feature is not fully implemented yet. use at your own risk.")); await context.SaveChangesAsync(); } }
public async Task SetLocale(EventContext e) { using (var context = new MikiContext()) { ChannelLanguage language = await context.Languages.FindAsync(e.Channel.Id.ToDbLong()); Locale locale = Locale.GetEntity(e.Channel.Id.ToDbLong()); if (!Locale.LocaleNames.ContainsKey(e.arguments.ToLower())) { await Utils.ErrorEmbed(locale, $"{e.arguments} is not a valid language. use `>listlocale` to check all languages available.").SendToChannel(e.Channel); return; } if (language == null) { language = context.Languages.Add(new ChannelLanguage() { EntityId = e.Channel.Id.ToDbLong(), Language = e.arguments.ToLower() }); } language.Language = Locale.LocaleNames[e.arguments.ToLower()]; await context.SaveChangesAsync(); await Utils.SuccessEmbed(e.Channel.GetLocale(), $"Set locale to `{e.arguments}`\n\n**WARNING:** this feature is not fully implemented yet. use at your own risk.").SendToChannel(e.Channel); } }
public async ValueTask SetLocaleAsync(long id, string iso3) { if (!IsValidIso(iso3)) { throw new LocaleNotFoundException(iso3); } var entity = new ChannelLanguage { EntityId = id, Language = iso3 }; var language = await repository.GetAsync(id); if (language == null) { await repository.AddAsync(entity); } else { await repository.EditAsync(entity); } await context.CommitAsync(); }
public bool HasString(string m) { using (var context = new MikiContext()) { ChannelLanguage l = context.Languages.Find(id); string lang; if (l == null) { lang = defaultResource; } else { lang = l.Language; } string output = Locales[lang].GetString(m); if (string.IsNullOrWhiteSpace(output)) { output = Locales[defaultResource].GetString(m); } return(!string.IsNullOrWhiteSpace(output)); } }
public string GetLanguage() { if (cache.TryGetValue(id, out string language)) { return(language); } else { using (var context = new MikiContext()) { ChannelLanguage l = context.Languages.Find(id); if (l != null) { cache.TryAdd(id, l.Language); return(l.Language); } } } return(cache.GetOrAdd(id, defaultResource)); }
public string GetString(string m, params object[] p) { using (var context = new MikiContext()) { ChannelLanguage l = context.Languages.Find(id); string lang; if (l == null) { lang = defaultResource; } else { lang = l.Language; } ResourceManager resources = Locales[lang]; string output = null; if (InternalStringAvailable(m, resources)) { output = InternalGetString(m, resources, p); if (string.IsNullOrWhiteSpace(output)) { output = InternalGetString(m, Locales[defaultResource], p); } } else { output = InternalGetString(m, Locales[defaultResource], p); } return(output); } }
/// <summary> /// Initiates a channel publishing process. /// </summary> /// <param name="channelPublisher">Instance of the object which implements IChannelPublisher.</param> /// <returns>Return publishing parameters.</returns> /// <remarks>Retrieves the channel info from the CRT, then executes callbacks for the supplied IChannelPublisher and finally updates the channel publishing status in CRT/AX.</remarks> public PublishingParameters PublishChannel(IChannelPublisher channelPublisher) { if (channelPublisher == null) { throw new ArgumentNullException(nameof(channelPublisher)); } if (this.onlineChannel.PublishStatus != OnlineChannelPublishStatusType.Published && this.onlineChannel.PublishStatus != OnlineChannelPublishStatusType.InProgress) { throw new ChannelNotPublishedException(Resources.ErrorChannelNotInPublishedState, this.onlineChannel.PublishStatus, this.onlineChannel.PublishStatusMessage); } IEnumerable <Category> categories; Dictionary <long, IEnumerable <AttributeCategory> > categoriesAttributes; // always load the categories but process them only if the channel is not published yet. try { this.LoadCategories(out categories, out categoriesAttributes); int categoriesCount = categories.Count(); NetTracer.Information(Resources.NumberOfReadCategoriesAndTheirAttributes, categoriesCount, categoriesAttributes.Count()); if (categoriesCount == 0) { throw new InvalidDataException(string.Format( "Navigation categories count returned is '{0}'. Error details {1}", categoriesCount, Resources.ErrorNoNavigationCategories)); } // Loading product attributes schema from CRT IEnumerable <AttributeProduct> productAttributes = this.LoadProductAttributes(); channelPublisher.OnValidateProductAttributes(productAttributes); int listingAttributesCount = productAttributes.Count(); NetTracer.Information(Resources.NumberOfReadAttributes, listingAttributesCount); if (listingAttributesCount == 0) { throw new InvalidDataException(string.Format( "Listing Attributes Count returned is '{0}'. Error details '{1}'", listingAttributesCount, Resources.ErrorNoSchemaAttributes)); } ChannelLanguage language = this.onlineChannel.ChannelLanguages.Single(l => l.IsDefault); CultureInfo culture = new CultureInfo(language.LanguageId); PublishingParameters parameters = new PublishingParameters { Categories = categories, CategoriesAttributes = categoriesAttributes, ProductsAttributes = productAttributes, ChannelDefaultCulture = culture, GiftCartItemId = this.channelManager.GetChannelConfiguration().GiftCardItemId }; if (this.onlineChannel.PublishStatus == OnlineChannelPublishStatusType.InProgress) { channelPublisher.OnChannelInformationAvailable(parameters, true); this.channelManager.UpdateOnlineChannelPublishStatus(OnlineChannelPublishStatusType.Published, null); } else { channelPublisher.OnChannelInformationAvailable(parameters, false); } return(parameters); } catch (Exception ex) { RetailLogger.Log.EcommercePlatformChannelPublishFailure(ex); string error = string.Format(CultureInfo.InvariantCulture, Resources.ErrorChannelPublishingFailed, ex.Message, DateTime.Now); this.channelManager.UpdateOnlineChannelPublishStatus(OnlineChannelPublishStatusType.Failed, error); throw; } }