| 1 | /* |
|---|
| 2 | * $Id$ |
|---|
| 3 | * Copyright 2008 The Eraser Project |
|---|
| 4 | * Original Author: Kasra Nassiri <cjax@users.sourceforge.net> |
|---|
| 5 | * Modified By: Joel Low <lowjoel@users.sourceforge.net> |
|---|
| 6 | * |
|---|
| 7 | * This file is part of Eraser. |
|---|
| 8 | * |
|---|
| 9 | * Eraser is free software: you can redistribute it and/or modify it under the |
|---|
| 10 | * terms of the GNU General Public License as published by the Free Software |
|---|
| 11 | * Foundation, either version 3 of the License, or (at your option) any later |
|---|
| 12 | * version. |
|---|
| 13 | * |
|---|
| 14 | * Eraser is distributed in the hope that it will be useful, but WITHOUT ANY |
|---|
| 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
|---|
| 16 | * A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
|---|
| 17 | * |
|---|
| 18 | * A copy of the GNU General Public License can be found at |
|---|
| 19 | * <http://www.gnu.org/licenses/>. |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | using System; |
|---|
| 23 | using System.Collections.Generic; |
|---|
| 24 | using System.Text; |
|---|
| 25 | using System.Globalization; |
|---|
| 26 | using System.Reflection; |
|---|
| 27 | using System.IO; |
|---|
| 28 | |
|---|
| 29 | namespace Eraser.Manager |
|---|
| 30 | { |
|---|
| 31 | /// <summary> |
|---|
| 32 | /// Basic language class holding the language-related subset of the CultureInfo class |
|---|
| 33 | /// </summary> |
|---|
| 34 | public class Language |
|---|
| 35 | { |
|---|
| 36 | /// <summary> |
|---|
| 37 | /// Constructor. |
|---|
| 38 | /// </summary> |
|---|
| 39 | /// <param name="info">The culture information structure to retrieve language |
|---|
| 40 | /// information from.</param> |
|---|
| 41 | public Language(CultureInfo info) |
|---|
| 42 | { |
|---|
| 43 | culture = info; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | public override string ToString() |
|---|
| 47 | { |
|---|
| 48 | return culture.DisplayName; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | /// <summary> |
|---|
| 52 | /// Gets the culture name in the format "<languagecode2>-<country/regioncode2>". |
|---|
| 53 | /// |
|---|
| 54 | /// The culture name in the format "<languagecode2>-<country/regioncode2>", where |
|---|
| 55 | /// <languagecode2> is a lowercase two-letter code derived from ISO 639-1 and |
|---|
| 56 | /// <country/regioncode2> is an uppercase two-letter code derived from ISO 3166. |
|---|
| 57 | /// </summary> |
|---|
| 58 | public string Name |
|---|
| 59 | { |
|---|
| 60 | get { return culture.Name; } |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | /// <summary> |
|---|
| 64 | /// Gets the culture name in the format "<languagefull> (<country/regionfull>)" |
|---|
| 65 | /// in the language of the localized version of .NET Framework. |
|---|
| 66 | /// |
|---|
| 67 | /// The culture name in the format "<languagefull> (<country/regionfull>)" in |
|---|
| 68 | /// the language of the localized version of .NET Framework, where <languagefull> |
|---|
| 69 | /// is the full name of the language and <country/regionfull> is the full name |
|---|
| 70 | /// of the country/region. |
|---|
| 71 | /// </summary> |
|---|
| 72 | public string DisplayName |
|---|
| 73 | { |
|---|
| 74 | get { return culture.DisplayName; } |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | /// <summary> |
|---|
| 78 | /// Gets the culture name in the format "<languagefull> (<country/regionfull>)" |
|---|
| 79 | /// in English. |
|---|
| 80 | /// |
|---|
| 81 | /// The culture name in the format "<languagefull> (<country/regionfull>)" in |
|---|
| 82 | /// English, where <languagefull> is the full name of the language and |
|---|
| 83 | /// <country/regionfull> is the full name of the country/region. |
|---|
| 84 | /// </summary> |
|---|
| 85 | public string EnglishName |
|---|
| 86 | { |
|---|
| 87 | get { return culture.EnglishName; } |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | /// <summary> |
|---|
| 91 | /// Converts the current Language object into a .NET CultureInfo object. |
|---|
| 92 | /// </summary> |
|---|
| 93 | /// <param name="lang">The language object being converted.</param> |
|---|
| 94 | /// <returns>A CultureInfo object, containing the data for the given language.</returns> |
|---|
| 95 | public static explicit operator CultureInfo(Language lang) |
|---|
| 96 | { |
|---|
| 97 | return lang.culture; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | public override int GetHashCode() |
|---|
| 101 | { |
|---|
| 102 | return culture.GetHashCode(); |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | CultureInfo culture; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | /// <summary> |
|---|
| 109 | /// A class managing all plugins dealing with languages. |
|---|
| 110 | /// </summary> |
|---|
| 111 | public static class LanguageManager |
|---|
| 112 | { |
|---|
| 113 | /// <summary> |
|---|
| 114 | /// Retrieves all present language plugins |
|---|
| 115 | /// </summary> |
|---|
| 116 | /// <returns>A list, with an instance of each Language class</returns> |
|---|
| 117 | public static IList<Language> Items |
|---|
| 118 | { |
|---|
| 119 | get |
|---|
| 120 | { |
|---|
| 121 | List<Language> result = new List<Language>(); |
|---|
| 122 | foreach (CultureInfo info in CultureInfo.GetCultures(CultureTypes.AllCultures)) |
|---|
| 123 | { |
|---|
| 124 | if (string.IsNullOrEmpty(info.Name)) |
|---|
| 125 | continue; |
|---|
| 126 | else if (new DirectoryInfo(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + |
|---|
| 127 | Path.DirectorySeparatorChar + info.Name).Exists) |
|---|
| 128 | result.Add(new Language(info)); |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | //Last resort |
|---|
| 132 | if (result.Count == 0) |
|---|
| 133 | result.Add(new Language(CultureInfo.GetCultureInfo("EN"))); |
|---|
| 134 | return result; |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | } |
|---|
| 138 | } |
|---|