Exemple #1
0
 /// <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;
     }
 }