2 * Copyright (C) 2006-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 using System.Collections;
26 namespace TeamXBMC.TranslatorCore
29 /// Object to communicate with the gui.
31 public sealed class TranslationManager
33 private TranslatorArray strings = new TranslatorArray();
34 private static TranslationManager instance=null;
36 private TranslationManager()
42 /// Loads the current language
44 public void Initialize()
50 #region Language file processing
53 /// Create a new language
55 public void CreateLanguage(string name)
57 if (File.Exists(Settings.Instance.LanguageFolder+@"\"+name+@"\strings.xml"))
58 throw new TranslatorException("The language \""+name+"\" already exists.");
62 Directory.CreateDirectory(Settings.Instance.LanguageFolder+@"\"+name);
66 throw new TranslatorException("Unable to create the directory "+Settings.Instance.LanguageFolder+@"\"+name, e);
70 // Save an empty strings.xml file
71 StringArray stringsNew=new StringArray();
72 stringsNew.Save(Settings.Instance.LanguageFolder+@"\"+name+@"\strings.xml");
74 LanguageInfo langinfo=new LanguageInfo();
75 langinfo.Save(Settings.Instance.LanguageFolder+@"\"+name+@"\langinfo.xml");
79 /// Save the current language
81 public void SaveTranslated()
91 /// Gets the instance of the TranslationManager
93 public static TranslationManager Instance
99 instance=new TranslationManager();
107 /// Get the strings of the current language with the state translated
109 public TranslatorArray Translated
113 strings.Enumerator=TranslatorArrayEnumerator.Translated;
119 /// Get the strings of the current language with the state untranslated
121 public TranslatorArray Untranslated
125 strings.Enumerator=TranslatorArrayEnumerator.Untranslated;
131 /// Get the strings of the current language with the state changed
133 public TranslatorArray Changed
137 strings.Enumerator=TranslatorArrayEnumerator.Changed;
143 /// Get all strings of the current language
145 public TranslatorArray All
149 strings.Enumerator=TranslatorArrayEnumerator.All;
155 /// Get the name of the current language
157 public string LanguageTranslated
159 get { return Settings.Instance.Language; }
163 /// Get the name of the master language
165 public string LanguageOriginal
167 get { return Settings.Instance.LanguageOriginal; }
171 /// Get all available languages
173 public string[] Languages
177 string root=Settings.Instance.LanguageFolder;
178 string[] dirs=Directory.GetDirectories(root);
179 ArrayList languages=new ArrayList();
181 foreach (string dir in dirs)
183 if (File.Exists(dir+@"\strings.xml"))
185 // Extract language name from path
186 string language=dir.Substring(root.Length+1, dir.Length-root.Length-1);
187 if (!language.Equals(Settings.Instance.LanguageOriginal) )
188 languages.Add(language);
192 return (string[])languages.ToArray(typeof(string));
197 /// Returns true if the currently edited language file is has been changed by the user
199 public bool IsModified
201 get { return strings.IsModified; }