Exemple #1
0
        public bool TryLocalizeErrorCode(string code, out string localizedString, params object[] codeParams)
        {
            try
            {
                if (!string.IsNullOrEmpty(code))
                {
                    if (codeParams == null)
                    {
                        var localizeResult = m_localizationManager.Translate(LocTranslationSource.File, m_localization.GetRequestCulture(), Scope, code);
                        localizedString = localizeResult.Value;
                        return(!localizeResult.ResourceNotFound);
                    }
                    else
                    {
                        var localizationParams = new object[codeParams.Length];
                        for (var i = 0; i < codeParams.Length; i++)
                        {
                            localizationParams[i] = LocalizeErrorCode(codeParams[i].ToString());
                        }

                        var localizeResult = m_localizationManager.TranslateFormat(LocTranslationSource.File, m_localization.GetRequestCulture(), Scope, code, localizationParams);
                        localizedString = localizeResult.Value;
                        return(!localizeResult.ResourceNotFound);
                    }
                }
            }
            catch (Exception e) when(e is LocalizationLibraryException || e is TranslateException)
            {
                if (m_logger.IsEnabled(LogLevel.Warning))
                {
                    m_logger.LogWarning("Translation for main service code '{0}' not found", code);
                }
            }

            localizedString = code;
            return(false);
        }
Exemple #2
0
        public LocalizedString Translate(string text, string scope, LocTranslationSource translationSource)
        {
            var requestCulture = GetRequestCulture();

            return(m_localizationManager.Translate(translationSource, requestCulture, scope, text));
        }
 public LocalizedString Translate(
     LocTranslationSource translationSource, string text, CultureInfo cultureInfo = null, string scope = null
     )
 {
     return(m_localizationManager.Translate(translationSource, text, cultureInfo, scope));
 }
Exemple #4
0
 LocalizedString IStringLocalizer.this[string name] =>
 m_autoLocalizationManager.Translate(m_location, RequestCulture(), m_baseName, name);