/// ------------------------------------------------------------------------------------ /// <summary> /// Updates the value for the specified translation unit with the specified new value. /// </summary> /// ------------------------------------------------------------------------------------ private TMXTransUnit UpdateValue(TMXTransUnit tu, string newValue, LocalizingInfo locInfo, string tuId) { newValue = newValue ?? string.Empty; // Get rid of the variant we are about to set if it is present. // If no variants remain get rid of the whole thing. // Later we will create whatever we need. if (tu != null) { var tuv = tu.GetVariantForLang(locInfo.LangId); if (tuv != null) { // don't need to update if the value hasn't changed if (tuv.Value == newValue) { return(tu); } _updated = true; tu.RemoveVariant(tuv); if (tu.Variants.Count == 0) { _tmxDoc.RemoveTransUnit(tu); tu = null; // so we will make a new one if needed. } } } if (newValue == string.Empty) { return(tu); } // Create a new entry if needed. if (tu == null) { tu = new TMXTransUnit(); tu.Id = tuId; _tmxDoc.AddTransUnit(tu); } tu.AddOrReplaceVariant(locInfo.LangId, newValue); _updated = true; return(tu); }
/// ------------------------------------------------------------------------------------ /// <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(TMXTransUnit 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 alphabetical 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); }
private static string GetDefaultVariantValue(TMXTransUnit tu) { var variant = tu.GetVariantForLang(LocalizationManager.kDefaultLang); return(variant?.Value); }