Esempio n. 1
0
        public string GetText(string key)
        {
            if (_translations == null)
            {
                _translations = _cmsApiProxy.GetTranslations().Result;
            }

            return(_translations.SingleOrDefault(t => t.Title.Rendered == key)?.Translation_text);
        }
        public async Task <IActionResult> TranslationUpdate([FromBody] CmsPostWebHookApiModel model)
        {
            _cmsApiProxy.RemoveTranslationsCache();
            var translations = await _cmsApiProxy.GetTranslations();

            _logger.LogInformation("Cleared and renewed cache for {Count} translations.", translations.Count);

            return(Ok());
        }
        public async Task <IActionResult> GetTranslations([FromQuery] string lang)
        {
            if (string.IsNullOrEmpty(lang))
            {
                lang = CmsVariable.DefaultLanguageCode;
            }

            if (_translations == null)
            {
                _translations = await _apiProxy.GetTranslations();
            }

            const int cacheHeaderMaxAgeTimeInMinutes = 60;

            Response.Headers.Add("Cache-Control", $"public,max-age={cacheHeaderMaxAgeTimeInMinutes*60},must-revalidate");

            return(Ok(_translations.Where(t => t.LanguageCode == lang).Select(t => new TranslationApiModel
            {
                Key = t.Title?.Rendered?.ToLower(),
                Value = t.Translation_text
            }).ToList()));
        }