/// <summary> /// lokalizace objektu (LMData souboru) /// </summary> public static void Localize(lm_scorm root) { if (HttpContext.Current == null) return; adjustThreadCulture(); StringBuilder buf = new StringBuilder(); ResxFilesManager resx = new ResxFilesManager(root.PageInfo.FileName); if (resx == null) return; object[] objs; foreach (TranslateInfo info in toTranslate(root, new TranslateInfo())) switch (info.Typ) { case LocalizeType.string2string: //Lokalizovatelna String property, vysledkem lokalizace je lokalizovatelny LMLiteral string valStr = (string)info.Value; if (string.IsNullOrEmpty(valStr)) break; if (!valStr.StartsWith(localizeStringPrefix)) info.setValue(createLiteral(valStr)); else info.setValue(resx.propertyTolocalizedLiteral(info, valStr.Substring(localizeStringPrefix.Length))); break; case LocalizeType.items2string: //HTML: vysledkem lokalizace je jeden lokalizovatelny LMLiteral objs = (object[])info.Value; if (objs.Length == 0) break; if (objs.Length == 1 && objs[0] is LMLiteral) info.setValue(objs[0]); else { bool first = true; foreach (object res in localizeObjectList(objs, buf, resx)) { if (!first || !(res is LMLiteral)) throw new Exception(); first = true; info.setValue(res); } } break; case LocalizeType.items2items: //HTML a LMScormObj: vysledkem lokalizace je seznam lokalizovatelnych LMLiteral a LMScormObj objs = (object[])info.Value; if (objs.Length == 0) break; bool noLocalize = true; foreach (LMScormObj item in objs) if (item is trans || item is img) { noLocalize = false; break; } if (noLocalize) info.setValue(objs); else { List<LMScormObj> items = new List<LMScormObj>(); foreach (LMScormObj res in localizeObjectList(objs, buf, resx)) items.Add(res); LMScormObj[] resObjs = new LMScormObj[items.Count]; items.CopyTo(resObjs); info.setValue(resObjs); } break; } }
/// <summary> /// Prevod nelokalizovaneho seznamu LMLiteral, Img, Trans a LMScormObj objektu na lokalizovane LMLiterals /// </summary> static IEnumerable<LMScormObj> localizeObjectList(object[] objs, StringBuilder buf, ResxFilesManager resx) { resx.Clear(); if (objs == null || objs.Length == 0) yield break; foreach (LMScormObj item in objs) { if (item is LMLiteral) resx.append(((LMLiteral)item).text); else if (item is img) resx.append((img)item); else if (item is trans) { string txt; if (tryTransText((trans)item, out txt)) resx.append(item.varName, null, txt); } else { if (!resx.isEmpty()) { yield return resx.toLocalizedLiteral(); resx.Clear(); } yield return item; } } if (!resx.isEmpty()) yield return resx.toLocalizedLiteral(); }