public async Task <Dictionary <string, string> > Translations(string language) { var resources = await translationRepository.GetAll(); var result = resources.ToDictionary(x => x.Alias, x => x.Translations.FirstOrDefault(y => y.Language == language)?.Value); return(result); }
public ActionResult Index() { var models = db.GetAll(); List <TranslationViewmodel> vmmodels = new List <TranslationViewmodel>(); foreach (var model in models) { vmmodels.Add(MapModelToViewmodel(model)); } return(View(vmmodels)); }
public async Task <byte[]> GetFileExportAsync(string languageKey, string projectKey) { var translations = await _repository.GetAll(languageKey, projectKey); var translationRows = translations.Select(m => m.Map()).ToList(); using (var ms = new MemoryStream()) using (var writer = new StreamWriter(ms)) using (var csvWriter = new CsvWriter(writer, new Configuration { Delimiter = CultureInfo.CurrentUICulture.TextInfo.ListSeparator })) { writer.WriteLine("sep=" + CultureInfo.CurrentUICulture.TextInfo.ListSeparator); csvWriter.WriteHeader <ExportTranslation>(); csvWriter.NextRecord(); foreach (var item in translationRows) { csvWriter.WriteRecord(item); csvWriter.NextRecord(); } csvWriter.Flush(); await writer.FlushAsync(); return(ms.ToArray()); } }
/// <summary> /// Retrieves a translation for the language code associated with the current user. /// Throws an exception if found is not found for the given labelName. /// (Meaning the actual page label is missing, not the translation.) /// </summary> /// <param name="labelName"></param> /// <returns></returns> public static Translation GetTranslation(string labelName) { var userRepository = DependencyResolver.Current.GetService <IUserRepository>(); var currentUser = userRepository.GetSingle(HttpContext.Current.User.Identity.GetUserId()); var languageId = (int)Language.Default; if (currentUser != null) { languageId = currentUser.LanguageId; } var cache = HttpContext.Current.Cache; IEnumerable <Translation> translations = cache[GetCacheKey(languageId)] as IEnumerable <Translation>; if (translations == null) { translations = repository.GetAll(languageId); cache[GetCacheKey(languageId)] = translations; } var result = translations.SingleOrDefault(item => item.LabelName == labelName); if (result == null) { throw new ApplicationException("Label not found: " + labelName); } return(result); }
public async Task <IEnumerable <Translation> > Get(string languageKey, string projectKey) { var key = TranslationCacheKey.Create(languageKey, projectKey); IEnumerable <Translation> translations = null; if (_cache.TryGetValue(key.ToString(), out translations)) { return(translations); } await s_semaphoreSlim.WaitAsync(); try { if (_cache.TryGetValue(key.ToString(), out translations)) { return(translations.ToList()); } translations = await _repository.GetAll(languageKey, projectKey); var cacheExpirationOptions = new MemoryCacheEntryOptions(); cacheExpirationOptions.AbsoluteExpiration = DateTime.Now.AddHours(4); cacheExpirationOptions.Priority = CacheItemPriority.Normal; _cache.Set(key.ToString(), translations, cacheExpirationOptions); return(translations.ToList()); } finally { s_semaphoreSlim.Release(); } }
public ActionResult Index(int?lang = null) { int languageId = (int)Language.Default; if (lang != null) { languageId = (int)lang; } ViewBag.CurrentLanguage = (Language)languageId; ViewBag.ActiveTab = "translations"; var model = translationRepository.GetAll(languageId); return(View(model)); }
public IEnumerable <Translation> GetAll() { return(_TranslationRepository.GetAll()); }
public List <TranslationViewModel> TranslationIndex() { return(_translationRepository.GetAll().Select(_mapper.Map <TranslationViewModel>).ToList()); }
public ActionResult Index() { var model = db.GetAll(); return(View(model)); }