Exemplo n.º 1
0
        /// <summary>
        /// 移除指定的I18n实例
        /// </summary>
        /// <param name="option">待删除的option实例</param>
        public static void RemoveInstance(I18NOption option)
        {
            I18NOption fitKey = _i18nEntities.Keys.First(item => option.Equals(item));
            I18N       i18n;

            if (null != fitKey)
            {
                _i18nEntities.TryRemove(fitKey, out i18n);
                i18n?.Dispose();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 移除指定名称的I18n实例
        /// </summary>
        /// <param name="i18nName"></param>
        public static void RemoveInstance(string i18nName)
        {
            I18NOption fitKey = _i18nEntities.Keys.First(option => i18nName.Equals(option.Name));
            I18N       i18n;

            if (null != fitKey)
            {
                _i18nEntities.TryRemove(fitKey, out i18n);
                i18n?.Dispose();
            }
        }
Exemplo n.º 3
0
        private I18N(I18NOption option)
        {
            string languageName      = Thread.CurrentThread.CurrentCulture.Name;
            string resourceShortName = null;

            if (languageName.Equals(option.FirstLanguage))
            {
                resourceShortName = option.FirstLanguageFile;
            }
            else if (languageName.Equals(option.SecondLanguage))
            {
                resourceShortName = option.SecondLanguageFile;
            }
            else if (CommonConst.EnglishName.Equals(option.FirstLanguage) || CommonConst.EnglishName.Equals(option.SecondLanguage))
            {
                resourceShortName = CommonConst.EnglishResourceName;
            }
            else
            {
                string msgFormat = GetResourceItem("UnsupportedLanguage");
                throw new TestflowRuntimeException(CommonErrorCode.I18nRuntimeError, string.Format(msgFormat, languageName));
            }
            string resourceFullName = null;

            // 修改国际化为使用反射获取资源文件配置
            foreach (string resourceName in option.Assembly.GetManifestResourceNames())
            {
                if (resourceName.Equals(resourceShortName) || resourceName.Contains($".{resourceShortName}.resx") ||
                    resourceName.Contains($".{resourceShortName}.resources") ||
                    resourceName.Contains($"_{resourceShortName}.resx") ||
                    resourceName.Contains($"_{resourceShortName}.resources"))
                {
                    resourceFullName = resourceName.Remove(resourceName.LastIndexOf("."));
                    break;
                }
            }
            if (null == resourceFullName)
            {
                string msgFormat = GetResourceItem("ResourceNotExist");
                throw new TestflowRuntimeException(CommonErrorCode.I18nRuntimeError, string.Format(msgFormat, resourceShortName));
            }
            this._resourceManager = new ResourceManager(resourceFullName, option.Assembly);
        }
Exemplo n.º 4
0
 /// <summary>
 /// 判断两个Option实例是否相等
 /// </summary>
 public bool Equals(I18NOption comparer)
 {
     return(ReferenceEquals(Assembly, comparer.Assembly) && FirstLanguage.Equals(comparer.FirstLanguage) &&
            SecondLanguage.Equals(comparer.SecondLanguage) && FirstLanguageFile.Equals(comparer.FirstLanguageFile) &&
            SecondLanguageFile.Equals(comparer.SecondLanguageFile));
 }