Example #1
0
        public static void LocalizeToolStripItemCollection(Assembly a, int language_id, Control parent, ToolStripItemCollection collection)
        {
            LocalizationStringTable st = LocalizationUtils.GetStringTable(a, language_id);

            if (st != null && parent != null)
            {
                string form_name       = parent.Name;
                Type   type            = parent.GetType();
                string form_class_name = type.Name;
                st.LocalizeToolStripCollection(form_name, form_class_name, collection);
            }
        }
Example #2
0
        public static void LocalizeForm(Assembly assembly, int languageId, Control form)
        {
            LocalizationStringTable st = LocalizationUtils.GetStringTable(assembly, languageId);

            if (st != null)
            {
                string form_name       = form.Name;
                Type   type            = form.GetType();
                string form_class_name = type.Name;
                st.LocalizeControlTree(form_name, form_class_name, form, GetToolTip(form));
            }
        }
Example #3
0
        public static string LocalizeDialogItem(Assembly assembly, int languageId, string key, string english)
        {
            // If Rhino set the CurrentUICulture correctly, we could use System.Threading.Thread.CurrentUICulture
            // and not have any dependencies on Rhino. This would allow for use of this DLL in any RMA product
            LocalizationStringTable st = GetStringTable(assembly, languageId);

            // No string table with the requested languaeId so just return the English string
            if (null != st && null != st.DialogList)
            {
                string s;
                if (st.DialogList.TryGetValue(key, out s))
                {
                    return(s);
                }
            }
            return(english);
        }
Example #4
0
        public LocalizationStringTable GetStringTable(Assembly a)
        {
            string key = a.Location;

            if (string.IsNullOrEmpty(key))
            {
                return(null);
            }

            LocalizationStringTable st;

            if (m_string_tables.TryGetValue(key, out st))
            {
                return(st);
            }

            // 18 July 2012 S. Baer
            // In the case that two threads are attempting to create the string
            // table at the same time, use a syncronization lock to only allow
            // one thread in the following block at any time
            lock (m_sync_object)
            {
                // perform the "TryGet" again in case a second thread was
                // blocked while the string table was being build
                if (m_string_tables.TryGetValue(key, out st))
                {
                    return(st);
                }

                // If we get here, the key does not exist in the dictionary.
                // Add a new string table
                st = new LocalizationStringTable();
                if (!st.LoadFromFile(a, m_language_id))
                {
                    // If string table fails to load then set it to null so that
                    // the next call which looks for this string table will return
                    // the null string table instead of searching the disk or assemblies
                    // embedded resources for the file
                    st = null;
                }

                m_string_tables[key] = st;
            }

            return(st);
        }
Example #5
0
        public static string LocalizeCommandName(Assembly assembly, int languageId, string english)
        {
            // If Rhino set the CurrentUICulture correctly, we could use System.Threading.Thread.CurrentUICulture
            // and not have any dependencies on Rhino. This would allow for use of this DLL in any RMA product
            LocalizationStringTable st = GetStringTable(assembly, languageId);

            // No string table with the requested languaeId so just return the English string
            if (null == st)
            {
                return(english);
            }
            string loc_str;

            if (!st.CommandList.TryGetValue(english, out loc_str) || string.IsNullOrEmpty(loc_str))
            {
                loc_str = english;
            }
            return(loc_str);
        }
Example #6
0
        public static string LocalizeString(Assembly assembly, int languageId, string english, int contextId)
        {
            // If Rhino set the CurrentUICulture correctly, we could use System.Threading.Thread.CurrentUICulture
            // and not have any dependencies on Rhino. This would allow for use of this DLL in any RMA product
            LocalizationStringTable st = GetStringTable(assembly, languageId);

            // No string table with the requested languaeId so just return the English string
            if (null == st)
            {
                return(english);
            }
            // 16 September 2010 John Morse
            // Need to massage the English string to compensate for string extractor limitations
            //
            // Make a copy of the English string so it can get messaged to form a proper key string
            StringBuilder key = new StringBuilder(english);
            // Check for leading spaces and save the number of spaces removed (iStart)
            int iStart;

            for (iStart = 0; key[iStart] == ' '; iStart++)
            {
            }
            if (iStart > 0)
            {
                key.Remove(0, iStart);
            }
            // Check for trailing spaces and save the number of spaces removed (jEnd - iEnd)
            int iEnd = key.Length - 1, jEnd;

            for (jEnd = iEnd; key[iEnd] == ' '; iEnd--)
            {
            }
            if (jEnd > iEnd)
            {
                key.Remove(iEnd + 1, jEnd - iEnd);
            }
            // If string to localize contains special characters then replace them with \\ versions since
            // \<char> is written to the XML file and used as a key
            //
            bool bN = english.Contains("\n");

            if (bN)
            {
                key.Replace("\n", "\\n");
            }
            bool bR = english.Contains("\r");

            if (bR)
            {
                key.Replace("\r", "\\r");
            }
            bool bT = english.Contains("\t");

            if (bT)
            {
                key.Replace("\t", "\\t");
            }
            bool bBS = english.Contains("\\");

            if (bBS)
            {
                key.Replace("\\", "\\\\");
            }
            bool bQuot = english.Contains("\"");

            if (bQuot)
            {
                key.Replace("\"", "\\\"");
            }

            if (contextId >= 0)
            {
                key.Append("[[");
                key.Append(contextId.ToString(CultureInfo.InvariantCulture));
                key.Append("]]");
            }
            string loc_str;

            if (!st.StringList.TryGetValue(key.ToString(), out loc_str) || string.IsNullOrEmpty(loc_str))
            {
                loc_str = english;
            }
            else if (iStart > 0 || jEnd > iEnd || bN || bR || bT || bQuot || bBS)
            {
                // String was massaged so reverse the process
                StringBuilder _loc_str = new StringBuilder(loc_str);
                // Pad front of string with number of spaces removed
                if (iStart > 0)
                {
                    _loc_str.Insert(0, " ", iStart);
                }
                // Pad end of string with number of spaces removed
                if (jEnd > iEnd)
                {
                    _loc_str.Append(' ', jEnd - iEnd);
                }
                // If the English string contained special character then strip the extra \ so it can get expanded
                if (bN)
                {
                    _loc_str.Replace("\\n", "\n");
                }
                if (bR)
                {
                    _loc_str.Replace("\\r", "\r");
                }
                if (bT)
                {
                    _loc_str.Replace("\\t", "\t");
                }
                if (bBS)
                {
                    _loc_str.Replace("\\\\", "\\");
                }
                if (bQuot)
                {
                    _loc_str.Replace("\\\"", "\"");
                }
                // Make return string
                loc_str = _loc_str.ToString();
            }

            return(loc_str);
        }
    public LocalizationStringTable GetStringTable(Assembly a)
    {
      string key = a.Location;
      if (string.IsNullOrEmpty(key))
        return null;

      LocalizationStringTable st;
      if (m_string_tables.TryGetValue(key, out st))
        return st;

      // 18 July 2012 S. Baer
      // In the case that two threads are attempting to create the string
      // table at the same time, use a syncronization lock to only allow
      // one thread in the following block at any time
      lock (m_sync_object)
      {
        // perform the "TryGet" again in case a second thread was
        // blocked while the string table was being build
        if (m_string_tables.TryGetValue(key, out st))
          return st;

        // If we get here, the key does not exist in the dictionary.
        // Add a new string table
        st = new LocalizationStringTable();
        if (!st.LoadFromFile(a, m_language_id))
        {
          // If string table fails to load then set it to null so that
          // the next call which looks for this string table will return
          // the null string table instead of searching the disk or assemblies
          // embedded resources for the file
          st = null;
        }

        m_string_tables[key] = st;
      }

      return st;
    }
 public LocalizationStringTable GetStringTable(Assembly a)
 {
   string key = a.Location;
   LocalizationStringTable st;
   if (m_string_tables.TryGetValue(key, out st))
     return st;
   // If we get here, the key does not exist in the dictionary.
   // Add a new string table
   st = new LocalizationStringTable();
   if (!st.LoadFromFile(a, m_language_id))
   {
     // If string table fails to load then set it to null so that
     // the next call which looks for this string table will return
     // the null string table instead of searching the disk or assemblies
     // embedded resources for the file
     st = null;
   }
   m_string_tables.Add(key, st);
   return st;
 }