Example #1
0
        /// <summary>
        /// When all but the last part of the id changed, this can help reunite things
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        internal TransUnit GetTransUnitForOrphan(TransUnit orphan)
        {
            var terminalIdToMatch  = LocalizedStringCache.GetTerminalIdPart(orphan.Id);
            var defaultTextToMatch = GetDefaultVariantValue(orphan);

            return(_transUnits.FirstOrDefault(tu => LocalizedStringCache.GetTerminalIdPart(tu.Id) == terminalIdToMatch && GetDefaultVariantValue(tu) == defaultTextToMatch));
        }
Example #2
0
        string GetDefaultVariantValue(TransUnit tu)
        {
            var variant = tu.GetVariantForLang(LocalizationManager.kDefaultLang);

            if (variant == null)
            {
                return(null);
            }
            return(variant.Value);
        }
Example #3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Removes the specified translation unit.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        internal void RemoveTransUnit(TransUnit tu)
        {
            if (tu == null)
            {
                return;
            }

            if (_transUnits.Contains(tu))
            {
                _transUnits.Remove(tu);
            }
            else if (tu.Id != null)
            {
                var tmptu = GetTransUnitForId(tu.Id);
                if (tmptu != null)
                {
                    _transUnits.Remove(tmptu);
                }
            }
        }
Example #4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// If a translation unit does not already exist for the id in the specified
        /// translation unit, then the translation unit is added. Otherwise, if the variant
        /// for the specified language does not exist in the translation unit, it is added.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        internal void AddTransUnitOrVariantFromExisting(TransUnit tu, string langId)
        {
            var variantToAdd = tu.GetVariantForLang(langId);

            if (variantToAdd == null || AddTransUnit(tu))
            {
                return;
            }

            var existingTu = GetTransUnitForId(tu.Id);

            //notice, we don't care if there is already a string in there for this language
            //(that was the source of a previous bug), because the tmx of language X should
            //surely take precedence, as source of the translation, over other language's
            //tms files which, by virtue of their alphabetica order (e.g. arabic), came
            //first. This probably only effects English, as it has variants in all the other
            //languages. Previously, Arabic would be processed first, so when English came
            //along, it was too late.
            existingTu.AddOrReplaceVariant(variantToAdd);
        }
Example #5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Adds the specified translation unit.
        /// </summary>
        /// <param name="tu">The translation unit.</param>
        /// <returns>true if the translation unit was successfully added. Otherwise, false.</returns>
        /// ------------------------------------------------------------------------------------
        internal bool AddTransUnit(TransUnit tu)
        {
            if (tu == null || tu.IsEmpty)
            {
                return(false);
            }

            if (tu.Id == null)
            {
                tu.Id = (++_transUnitId).ToString();
            }

            // If a translation unit with the specified id already exists, then quit here.
            if (GetTransUnitForId(tu.Id) != null)
            {
                return(false);
            }

            _transUnits.Add(tu);
            return(true);
        }
Example #6
0
 /// <summary>
 /// When we change ids after people have already been localizing, we have a BIG PROBLEM.
 /// This helps with the common case were we just changed the hierarchical organizaiton of the id,
 /// that is, the parts of the id before th final '.'.
 /// </summary>
 /// <param name="id"></param>
 public TransUnit GetTransUnitForOrphan(TransUnit orphan)
 {
     return(Body.GetTransUnitForOrphan(orphan));
 }
Example #7
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Remove the specified translation unit.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public void RemoveTransUnit(TransUnit tu)
 {
     Body.RemoveTransUnit(tu);
 }
Example #8
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Adds the specified translation unit.
 /// </summary>
 /// <param name="tu">The translation unit.</param>
 /// <returns>true if the translation unit was successfully added. Otherwise, false.</returns>
 /// ------------------------------------------------------------------------------------
 public bool AddTransUnit(TransUnit tu)
 {
     return(Body.AddTransUnit(tu));
 }