コード例 #1
0
        internal static CultureInfo GetCultureInfo(string requestPath, out string requestPathWithoutUrlMappingName)
        {
            requestPathWithoutUrlMappingName = requestPath;

            int startIndex = requestPath.IndexOf('/', UrlUtils.PublicRootPath.Length) + 1;

            if (startIndex >= 0 && requestPath.Length > startIndex)
            {
                int endIndex = requestPath.IndexOf('/', startIndex + 1) - 1;
                if (endIndex >= 0)
                {
                    string urlMappingName = requestPath.Substring(startIndex, endIndex - startIndex + 1);

                    if (DataLocalizationFacade.UrlMappingNames.Contains(urlMappingName))
                    {
                        CultureInfo cultureInfo = DataLocalizationFacade.GetCultureInfoByUrlMappingName(urlMappingName);

                        bool exists = DataLocalizationFacade.ActiveLocalizationNames.Contains(cultureInfo.Name);

                        if (exists)
                        {
                            requestPathWithoutUrlMappingName = requestPath.Remove(startIndex - 1, endIndex - startIndex + 2);

                            return(cultureInfo);
                        }

                        return(null);
                    }
                }
            }

            return(DataLocalizationFacade.DefaultUrlMappingCulture);
        }
コード例 #2
0
 private CultureInfo[] GetSupportedCultures(Type interfaceType)
 {
     if (DataLocalizationFacade.IsLocalized(interfaceType))
     {
         return(DataLocalizationFacade.ActiveLocalizationCultures.ToArray());
     }
     return(new[] { CultureInfo.InvariantCulture });
 }
コード例 #3
0
        /// <exclude />
        public static CultureInfo MapByType(Type type)
        {
            if (DataLocalizationFacade.IsLocalized(type))
            {
                return(CurrentLocalizationScope);
            }

            return(CultureInfo.InvariantCulture);
        }
コード例 #4
0
        public IEnumerable <ReferenceFailingPropertyInfo> GetReferencingLocalizeFailingProperties(ILocalizedControlled data)
        {
            DataTypeDescriptor dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(data.DataSourceId.InterfaceType);

            IEnumerable <DataFieldDescriptor> requiredDataFieldDescriptors = dataTypeDescriptor.Fields.Where(f => f.ForeignKeyReferenceTypeName != null);

            foreach (DataFieldDescriptor dataFieldDescriptor in requiredDataFieldDescriptors)
            {
                Type referencedType = TypeManager.GetType(dataFieldDescriptor.ForeignKeyReferenceTypeName);
                if (!DataLocalizationFacade.IsLocalized(referencedType))
                {
                    continue;                                                      // No special handling for not localized data.
                }
                IData referencedData = data.GetReferenced(dataFieldDescriptor.Name);
                if (referencedData != null)
                {
                    continue;                         // Data has already been localized
                }
                bool optionalReferenceWithValue = false;
                if (dataFieldDescriptor.IsNullable)
                {
                    PropertyInfo propertyInfo = data.DataSourceId.InterfaceType.GetPropertiesRecursively().Single(f => f.Name == dataFieldDescriptor.Name);
                    object       value        = propertyInfo.GetValue(data, null);

                    if (value == null || object.Equals(value, dataFieldDescriptor.DefaultValue))
                    {
                        continue; // Optional reference is null;
                    }

                    optionalReferenceWithValue = true;
                }

                CultureInfo locale = data.DataSourceId.LocaleScope;

                using (new DataScope(locale))
                {
                    referencedData = data.GetReferenced(dataFieldDescriptor.Name);
                }

                ReferenceFailingPropertyInfo referenceFailingPropertyInfo = new ReferenceFailingPropertyInfo
                                                                            (
                    dataFieldDescriptor,
                    referencedType,
                    referencedData,
                    optionalReferenceWithValue
                                                                            );

                yield return(referenceFailingPropertyInfo);
            }
        }