Пример #1
0
        /// <summary>
        /// Returns correct pluralized string.
        /// </summary>
        /// <param name="number">Plural number.</param>
        /// <returns>Pluralized string or default string if not found.</returns>
        public LocalizedString GetPluralizedLocalizedString(int number)
        {
            var pluralizationKey = new PluralizationInterval(number, number);

            foreach (var pluralizedLocalizedString in m_pluralized)
            {
                if (pluralizedLocalizedString.Key.Equals(pluralizationKey))
                {
                    return(pluralizedLocalizedString.Value);
                }
            }

            return(m_defaultLocalizedString);
        }
Пример #2
0
        /// <summary>
        /// Adds new pluralized form of Localized string with its interval.
        /// </summary>
        /// <param name="pluralizationInterval">Interval when use this form of localized string.</param>
        /// <param name="localizedString">Assigned pluralized form.</param>
        /// <exception cref="PluralizedStringIntervalOverlapException">Thrown if Pluralized string already contains any
        /// sub-interval of paramater pluralizationInterval</exception>
        public void Add(PluralizationInterval pluralizationInterval, LocalizedString localizedString)
        {
            if (CheckOverlaping(pluralizationInterval))
            {
                var overlapErrorMsg = "Intervals are overlaping in the Pluralized string.";
                if (m_logger != null && m_logger.IsErrorEnabled())
                {
                    m_logger.LogError(overlapErrorMsg);
                }

                throw new PluralizedStringIntervalOverlapException(overlapErrorMsg);
            }

            m_pluralized.TryAdd(pluralizationInterval, localizedString);
        }
Пример #3
0
        /// <summary>
        /// Checks if given pluralizationInterval overlaps with already added intervals.
        /// </summary>
        /// <param name="pluralizationInterval">Interval to check.</param>
        /// <returns>True if overlap was found.</returns>
        private bool CheckOverlaping(PluralizationInterval pluralizationInterval)
        {
            Guard.ArgumentNotNull(nameof(pluralizationInterval), pluralizationInterval, m_logger);

            var pluralizedKeys = m_pluralized.Keys;

            foreach (var pluralizedKey in pluralizedKeys)
            {
                if (pluralizedKey.IsOverlaping(pluralizationInterval))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #4
0
        /// <summary>
        /// Checks if given pluralizationInterval overlaps with already added intervals.
        /// </summary>
        /// <param name="pluralizationInterval">Interval to check.</param>
        /// <returns>True if overlap was found.</returns>
        private bool CheckOverlaping(PluralizationInterval pluralizationInterval)
        {
            Guard.ArgumentNotNull(nameof(pluralizationInterval), pluralizationInterval, m_logger);

            var pluralizedIntervals = Intervals.Select(x => x.Interval);

            foreach (var pluralizedInterval in pluralizedIntervals)
            {
                if (pluralizedInterval.Start <= pluralizationInterval.End && pluralizationInterval.Start <= pluralizedInterval.End)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #5
0
        /// <summary>
        /// Determines whether the union of specified object with this is not empty.
        /// </summary>
        /// <param name="obj">Interval to test with this object.</param>
        /// <returns>true if union of intevals is not empty.</returns>
        /// <exception cref="NullReferenceException">Is thrown if obj is null.</exception>
        public bool IsOverlaping(PluralizationInterval obj)
        {
            Guard.ArgumentNotNull(nameof(obj), obj, m_logger);

            return(m_x <= obj.m_y && obj.m_x <= m_y);
        }