Пример #1
0
        public Tuple <string, string> MapToFieldName(string rawQuery, string language)
        {
            var metaResponse = _metaRepository.GetAll();

            if (metaResponse.Code != AppStatusCode.Ok)
            {
                return(null);
            }

            var metaKeys         = metaResponse.Data.SelectMany(m => m.Values);
            var metaTranslations = _jsonReader.GetFileContents <dynamic>("~/Localization/lang_" + language + ".json")["meta"];

            var mappedQuery = metaKeys.FirstOrDefault(k => ((string)metaTranslations[k]).Equals(rawQuery, StringComparison.InvariantCultureIgnoreCase));

            if (mappedQuery == null)
            {
                return(null);
            }

            var metaType     = mappedQuery.Substring(0, 3);
            var metaSubField = metaType == "cat" ? "Category" :
                               metaType == "cui" ? "Cuisine" : "Course";

            return(new Tuple <string, string>("Meta." + metaSubField, mappedQuery));
        }
Пример #2
0
        public string Translate(string area, string key, string langCode)
        {
            var translations = _jsonReader.GetFileContents <JObject>("~/Localization/lang_" + (langCode ?? "sv-SE") + ".json");

            var areaObj = translations[area];

            if (areaObj != null)
            {
                var translation = areaObj[key];
                if (translation != null)
                {
                    return(translation.Value <string>());
                }
            }

            return(string.Format("[{0}/{1}]", area, key));
        }
        public IHttpActionResult GetAll(string langCode)
        {
            if (string.IsNullOrEmpty(langCode))
            {
                return(BadRequest(AppStatusCode.InvalidInput, "Language code must be provided."));
            }

            var translations = _jsonReader.GetFileContents <dynamic>("~/Localization/lang_" + langCode + ".json");

            var response = new ActionResponse <dynamic>
            {
                Code = AppStatusCode.Ok,
                Data = translations
            };

            return(Ok(response));
        }