diff options
| author | LukePulverenti <luke.pulverenti@gmail.com> | 2013-02-20 20:33:05 -0500 |
|---|---|---|
| committer | LukePulverenti <luke.pulverenti@gmail.com> | 2013-02-20 20:33:05 -0500 |
| commit | 767cdc1f6f6a63ce997fc9476911e2c361f9d402 (patch) | |
| tree | 49add55976f895441167c66cfa95e5c7688d18ce /MediaBrowser.Controller/Localization | |
| parent | 845554722efaed872948a9e0f7202e3ef52f1b6e (diff) | |
Pushing missing changes
Diffstat (limited to 'MediaBrowser.Controller/Localization')
8 files changed, 838 insertions, 0 deletions
diff --git a/MediaBrowser.Controller/Localization/AURatingsDictionary.cs b/MediaBrowser.Controller/Localization/AURatingsDictionary.cs new file mode 100644 index 000000000..882302f10 --- /dev/null +++ b/MediaBrowser.Controller/Localization/AURatingsDictionary.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; + +namespace MediaBrowser.Controller.Localization +{ + /// <summary> + /// Class AURatingsDictionary + /// </summary> + public class AURatingsDictionary : Dictionary<string, int> + { + /// <summary> + /// Initializes a new instance of the <see cref="AURatingsDictionary" /> class. + /// </summary> + public AURatingsDictionary() + { + Add("AU-G", 1); + Add("AU-PG", 5); + Add("AU-M", 6); + Add("AU-M15+", 7); + Add("AU-R18+", 9); + Add("AU-X18+", 10); + } + } +} diff --git a/MediaBrowser.Controller/Localization/BaseStrings.cs b/MediaBrowser.Controller/Localization/BaseStrings.cs new file mode 100644 index 000000000..c76df7c7c --- /dev/null +++ b/MediaBrowser.Controller/Localization/BaseStrings.cs @@ -0,0 +1,290 @@ +using MediaBrowser.Common.Localization; +using System.ComponentModel.Composition; + +namespace MediaBrowser.Controller.Localization +{ + [Export(typeof(LocalizedStringData))] + public class BaseStrings : LocalizedStringData + { + public BaseStrings() + { + ThisVersion = "1.0002"; + Prefix = LocalizedStrings.BasePrefix; + } + + + + //Config Panel + public string ConfigConfig = "Configuration"; + public string VersionConfig = "Version"; + public string MediaOptionsConfig = "Media Options"; + public string ThemesConfig = "Theme Options"; + public string ParentalControlConfig = "Parental Control"; + public string ContinueConfig = "Continue"; + public string ResetDefaultsConfig = "Reset Defaults"; + public string ClearCacheConfig = "Clear Cache"; + public string UnlockConfig = "Unlock"; + public string GeneralConfig = "General"; + public string EnableScreenSaverConfig = "Screen Saver"; + public string SSTimeOutConfig = "Timeout (mins)"; + public string TrackingConfig = "Tracking"; + public string AssumeWatchedIfOlderThanConfig = "Assume Played If Older Than"; + public string MetadataConfig = "Metadata"; + public string EnableInternetProvidersConfig = "Allow Internet Providers"; + public string UpdatesConfig = "Updates"; + public string AutomaticUpdatesConfig = "Check For Updates"; + public string LoggingConfig = "Logging"; + public string BetaUpdatesConfig = "Beta Updates"; + public string GlobalConfig = "Global"; + public string EnableEHSConfig = "Enable EHS"; + public string ShowClockConfig = "Show Clock"; + public string DimUnselectedPostersConfig = "Dim Unselected Posters"; + public string HideFocusFrameConfig = "Hide Focus Frame"; + public string AlwaysShowDetailsConfig = "Always Show Details"; + public string ExcludeRemoteContentInSearchesConfig = "Exclude Remote Content In Searches"; + public string EnhancedMouseSupportConfig = "Enhanced Mouse Support"; + public string ViewsConfig = "Views"; + public string PosterGridSpacingConfig = "Poster Grid Spacing"; + public string ThumbWidthSplitConfig = "Thumb Width Split"; + public string BreadcrumbCountConfig = "Breadcrumb Count"; + public string ShowFanArtonViewsConfig = "Show Fan Art on Views"; + public string ShowInitialFolderBackgroundConfig = "Show Initial Folder Background"; + public string ShowThemeBackgroundConfig = "Show Theme Background"; + public string ShowHDOverlayonPostersConfig = "Show HD Overlay on Posters"; + public string ShowIcononRemoteContentConfig = "Show Icon on Remote Content"; + public string EnableAdvancedCmdsConfig = "Enable Advanced Commands"; + public string MediaTrackingConfig = "Media Tracking"; + public string RememberFolderIndexingConfig = "Remember Folder Indexing"; + public string ShowUnwatchedCountConfig = "Show Unplayed Count"; + public string WatchedIndicatoronFoldersConfig = "Played Indicator on Folders"; + public string HighlightUnwatchedItemsConfig = "Highlight Unplayed Items"; + public string WatchedIndicatoronVideosConfig = "Played Indicator on Items"; + public string WatchedIndicatorinDetailViewConfig = "Played Indicator in Detail View"; + public string DefaultToFirstUnwatchedItemConfig = "Default To First Unplayed Item"; + public string GeneralBehaviorConfig = "General Behavior"; + public string AllowNestedMovieFoldersConfig = "Allow Nested Movie Folders"; + public string AutoEnterSingleFolderItemsConfig = "Auto Enter Single Folder Items"; + public string MultipleFileBehaviorConfig = "Multiple File Behavior"; + public string TreatMultipleFilesAsSingleMovieConfig = "Treat Multiple Files As Single Movie"; + public string MultipleFileSizeLimitConfig = "Multiple File Size Limit"; + public string MBThemeConfig = "Media Browser Theme"; + public string VisualThemeConfig = "Visual Theme"; + public string ColorSchemeConfig = "Color Scheme *"; + public string FontSizeConfig = "Font Size *"; + public string RequiresRestartConfig = "* Requires a restart to take effect."; + public string ThemeSettingsConfig = "Theme Specific Settings"; + public string ShowConfigButtonConfig = "Show Config Button"; + public string AlphaBlendingConfig = "Alpha Blending"; + public string SecurityPINConfig = "Security PIN"; + public string PCUnlockedTxtConfig = "Parental Controls are Temporarily Unlocked. You cannot change values unless you re-lock."; + public string RelockBtnConfig = "Re-Lock"; + public string EnableParentalBlocksConfig = "Enable Parental Blocks"; + public string MaxAllowedRatingConfig = "Max Allowed Rating "; + public string BlockUnratedContentConfig = "Block Unrated Content"; + public string HideBlockedContentConfig = "Hide Blocked Content"; + public string UnlockonPINEntryConfig = "Unlock on PIN Entry"; + public string UnlockPeriodHoursConfig = "Unlock Period (Hours)"; + public string EnterNewPINConfig = "Enter New PIN"; + public string RandomizeBackdropConfig = "Randomize"; + public string RotateBackdropConfig = "Rotate"; + public string UpdateLibraryConfig = "Update Library"; + public string BackdropSettingsConfig = "Backdrop Settings"; + public string BackdropRotationIntervalConfig = "Rotation Time"; + public string BackdropTransitionIntervalConfig = "Transition Time"; + public string BackdropLoadDelayConfig = "Load Delay"; + public string AutoScrollTextConfig = "Auto Scroll Overview"; + public string SortYearsAscConfig = "Sort by Year in Ascending Order"; + public string AutoValidateConfig = "Automatically Validate Items"; + public string SaveLocalMetaConfig = "Save Locally"; + public string HideEmptyFoldersConfig = "Hide Empty TV Folders"; + + + //EHS + public string RecentlyWatchedEHS = "last played"; + public string RecentlyAddedEHS = "last added"; + public string RecentlyAddedUnwatchedEHS = "last added unplayed"; + public string WatchedEHS = "Played"; + public string AddedEHS = "Added"; + public string UnwatchedEHS = "Unplayed"; + public string AddedOnEHS = "Added on"; + public string OnEHS = "on"; + public string OfEHS = "of"; + public string NoItemsEHS = "No Items To Show"; + public string VariousEHS = "(various)"; + + //Context menu + public string CloseCMenu = "Close"; + public string PlayMenuCMenu = "Play Menu"; + public string ItemMenuCMenu = "Item Menu"; + public string PlayAllCMenu = "Play All"; + public string PlayAllFromHereCMenu = "Play All From Here"; + public string ResumeCMenu = "Resume"; + public string MarkUnwatchedCMenu = "Mark Unplayed"; + public string MarkWatchedCMenu = "Mark Played"; + public string ShufflePlayCMenu = "Shuffle Play"; + + //Media Detail Page + public string GeneralDetail = "General"; + public string ActorsDetail = "Actors"; + public string ArtistsDetail = "Artists"; + public string PlayDetail = "Play"; + public string ResumeDetail = "Resume"; + public string RefreshDetail = "Refresh"; + public string PlayTrailersDetail = "Trailer"; + public string CacheDetail = "Cache 2 xml"; + public string DeleteDetail = "Delete"; + public string TMDBRatingDetail = "TMDb Rating"; + public string OutOfDetail = "out of"; + public string DirectorDetail = "Director"; + public string ComposerDetail = "Composer"; + public string HostDetail = "Host"; + public string RuntimeDetail = "Runtime"; + public string NextItemDetail = "Next"; + public string PreviousItemDetail = "Previous"; + public string FirstAiredDetail = "First aired"; + public string LastPlayedDetail = "Last played"; + public string TrackNumberDetail = "Track"; + + public string DirectedByDetail = "Directed By: "; + public string WrittenByDetail = "Written By: "; + public string ComposedByDetail = "Composed By: "; + + //Display Prefs + public string ViewDispPref = "View"; + public string ViewSearch = "Search"; + public string CoverFlowDispPref = "Cover Flow"; + public string DetailDispPref = "Detail"; + public string PosterDispPref = "Poster"; + public string ThumbDispPref = "Thumb"; + public string ThumbStripDispPref = "Thumb Strip"; + public string ShowLabelsDispPref = "Show Labels"; + public string VerticalScrollDispPref = "Vertical Scroll"; + public string UseBannersDispPref = "Use Banners"; + public string UseCoverflowDispPref = "Use Coverflow Style"; + public string ThumbSizeDispPref = "Thumb Size"; + public string NameDispPref = "Name"; + public string DateDispPref = "Date"; + public string RatingDispPref = "User Rating"; + public string OfficialRatingDispPref = "Rating"; + public string RuntimeDispPref = "Runtime"; + public string UnWatchedDispPref = "Unplayed"; + public string YearDispPref = "Year"; + public string NoneDispPref = "None"; + public string PerformerDispPref = "Performer"; + public string ActorDispPref = "Actor"; + public string GenreDispPref = "Genre"; + public string DirectorDispPref = "Director"; + public string StudioDispPref = "Studio"; + + //Dialog boxes + //public string BrokenEnvironmentDial = "Application will now close due to broken MediaCenterEnvironment object, possibly due to 5 minutes of idle time and/or running with TVPack installed."; + //public string InitialConfigDial = "Initial configuration is complete, please restart Media Browser"; + //public string DeleteMediaDial = "Are you sure you wish to delete this media item?"; + //public string DeleteMediaCapDial = "Delete Confirmation"; + //public string NotDeletedDial = "Item NOT Deleted."; + //public string NotDeletedCapDial = "Delete Cancelled by User"; + //public string NotDelInvalidPathDial = "The selected media item cannot be deleted due to an invalid path. Or you may not have sufficient access rights to perform this command."; + //public string DelFailedDial = "Delete Failed"; + //public string NotDelUnknownDial = "The selected media item cannot be deleted due to an unknown error."; + //public string NotDelTypeDial = "The selected media item cannot be deleted due to its Item-Type or you have not enabled this feature in the configuration file."; + //public string FirstTimeDial = "As this is the first time you have run Media Browser please setup the inital configuration"; + //public string FirstTimeCapDial = "Configure"; + //public string EntryPointErrorDial = "Media Browser could not launch directly into "; + //public string EntryPointErrorCapDial = "Entrypoint Error"; + //public string CriticalErrorDial = "Media Browser encountered a critical error and had to shut down: "; + //public string CriticalErrorCapDial = "Critical Error"; + //public string ClearCacheErrorDial = "An error occured during the clearing of the cache, you may wish to manually clear it from {0} before restarting Media Browser"; + //public string RestartMBDial = "Please restart Media Browser"; + //public string ClearCacheDial = "Are you sure you wish to clear the cache?\nThis will erase all cached and downloaded information and images."; + //public string ClearCacheCapDial = "Clear Cache"; + //public string CacheClearedDial = "Cache Cleared"; + //public string ResetConfigDial = "Are you sure you wish to reset all configuration to defaults?"; + //public string ResetConfigCapDial = "Reset Configuration"; + //public string ConfigResetDial = "Configuration Reset"; + //public string UpdateMBDial = "Please visit www.mediabrowser.tv/download to install the new version."; + //public string UpdateMBCapDial = "Update Available"; + //public string UpdateMBExtDial = "There is an update available for Media Browser. Please update Media Browser next time you are at your MediaCenter PC."; + //public string DLUpdateFailDial = "Media Browser will operate normally and prompt you again the next time you load it."; + //public string DLUpdateFailCapDial = "Update Download Failed"; + //public string UpdateSuccessDial = "Media Browser must now exit to apply the update. It will restart automatically when it is done"; + //public string UpdateSuccessCapDial = "Update Downloaded"; + //public string CustomErrorDial = "Customisation Error"; + //public string ConfigErrorDial = "Reset to default?"; + //public string ConfigErrorCapDial = "Error in configuration file"; + //public string ContentErrorDial = "There was a problem playing the content. Check location exists"; + //public string ContentErrorCapDial = "Content Error"; + //public string CannotMaximizeDial = "We can not maximize the window! This is a known bug with Windows 7 and TV Pack, you will have to restart Media Browser!"; + //public string IncorrectPINDial = "Incorrect PIN Entered"; + //public string ContentProtected = "Content Protected"; + //public string CantChangePINDial = "Cannot Change PIN"; + //public string LibraryUnlockedDial = "Library Temporarily Unlocked. Will Re-Lock in {0} Hour(s) or on Application Re-Start"; + //public string LibraryUnlockedCapDial = "Unlock"; + //public string PINChangedDial = "PIN Successfully Changed"; + //public string PINChangedCapDial = "PIN Change"; + //public string EnterPINToViewDial = "Please Enter PIN to View Protected Content"; + //public string EnterPINToPlayDial = "Please Enter PIN to Play Protected Content"; + //public string EnterCurrentPINDial = "Please Enter CURRENT PIN."; + //public string EnterNewPINDial = "Please Enter NEW PIN (exactly 4 digits)."; + //public string EnterPINDial = "Please Enter PIN to Unlock Library"; + //public string NoContentDial = "No Content that can be played in this context."; + //public string FontsMissingDial = "CustomFonts.mcml as been patched with missing values"; + //public string StyleMissingDial = "{0} has been patched with missing values"; + //public string ManualRefreshDial = "Library Update Started. Will proceed in the background."; + //public string ForcedRebuildDial = "Your library is currently being migrated by the service. The service will re-start when it is finished and you may then run Media Browser."; + //public string ForcedRebuildCapDial = "Library Migration"; + //public string RefreshFailedDial = "The last service refresh process failed. Please run a manual refresh from the service."; + //public string RefreshFailedCapDial = "Service Refresh Failed"; + //public string RebuildNecDial = "This version of Media Browser requires a re-build of your library. It has started automatically in the service. Some information may be incomplete until this process finishes."; + //public string MigrateNecDial = "This version of Media Browser requires a migration of your library. It has started automatically in the service. The service will restart when it is complete and you may then run Media Browser."; + //public string RebuildFailedDial = "There was an error attempting to tell the service to re-build your library. Please run the service and do a manual refresh with the cache clear options selected."; + //public string MigrateFailedDial = "There was an error attempting to tell the service to re-build your library. Please run the service and do a manual refresh with the cache clear options selected."; + //public string RefreshFolderDial = "Refresh all contents too?"; + //public string RefreshFolderCapDial = "Refresh Folder"; + + //Generic + public string Restartstr = "Restart"; + public string Errorstr = "Error"; + public string Playstr = "Play"; + public string MinutesStr = "mins"; //Minutes abbreviation + public string HoursStr = "hrs"; //Hours abbreviation + public string EndsStr = "Ends"; + public string KBsStr = "Kbps"; //Kilobytes per second + public string FrameRateStr = "fps"; //Frames per second + public string AtStr = "at"; //x at y, e.g. 1920x1080 at 25 fps + public string Rated = "Rated"; + public string Or = "Or "; + public string Lower = "Lower"; + public string Higher = "Higher"; + public string Search = "Search"; + public string Cancel = "Cancel"; + public string TitleContains = "Title Contains "; + public string Any = "Any"; + + //Search + public string IncludeNested = "Include Subfolders"; + public string UnwatchedOnly = "Include Only Unwatched"; + public string FilterByRated = "Filter by Rating"; + + //Profiler + public string WelcomeProf = "Welcome to Media Browser"; + public string ProfilerTimeProf = "{1} took {2} seconds."; + public string RefreshProf = "Refresh"; + public string SetWatchedProf = "Set Played {0}"; + public string RefreshFolderProf = "Refresh Folder and all Contents of"; + public string ClearWatchedProf = "Clear Played {0}"; + public string FullRefreshProf = "Full Library Refresh"; + public string FullValidationProf = "Full Library Validation"; + public string FastRefreshProf = "Fast Metadata refresh"; + public string SlowRefresh = "Slow Metadata refresh"; + public string ImageRefresh = "Image refresh"; + public string PluginUpdateProf = "An update is available for plug-in {0}"; + public string NoPluginUpdateProf = "No Plugin Updates Currently Available."; + public string LibraryUnLockedProf = "Library Temporarily UnLocked. Will Re-Lock in {0} Hour(s)"; + public string LibraryReLockedProf = "Library Re-Locked"; + + //Messages + public string FullRefreshMsg = "Updating Media Library..."; + public string FullRefreshFinishedMsg = "Library update complete"; + + } +} diff --git a/MediaBrowser.Controller/Localization/GBRatingsDictionary.cs b/MediaBrowser.Controller/Localization/GBRatingsDictionary.cs new file mode 100644 index 000000000..414abdd59 --- /dev/null +++ b/MediaBrowser.Controller/Localization/GBRatingsDictionary.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; + +namespace MediaBrowser.Controller.Localization +{ + /// <summary> + /// Class GBRatingsDictionary + /// </summary> + public class GBRatingsDictionary : Dictionary<string, int> + { + /// <summary> + /// Initializes a new instance of the <see cref="GBRatingsDictionary" /> class. + /// </summary> + public GBRatingsDictionary() + { + Add("GB-U", 1); + Add("GB-PG", 5); + Add("GB-12", 6); + Add("GB-12A", 7); + Add("GB-15", 8); + Add("GB-18", 9); + Add("GB-R18", 15); + } + } +} diff --git a/MediaBrowser.Controller/Localization/LocalizedStrings.cs b/MediaBrowser.Controller/Localization/LocalizedStrings.cs new file mode 100644 index 000000000..b7e66f095 --- /dev/null +++ b/MediaBrowser.Controller/Localization/LocalizedStrings.cs @@ -0,0 +1,155 @@ +using MediaBrowser.Common.Localization; +using MediaBrowser.Common.Logging; +using System; +using System.Collections.Concurrent; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Xml.Serialization; + +namespace MediaBrowser.Controller.Localization +{ + /// <summary> + /// Class LocalizedStrings + /// </summary> + public class LocalizedStrings + { + /// <summary> + /// The base prefix + /// </summary> + public const string BasePrefix = "base-"; + /// <summary> + /// The local strings + /// </summary> + protected ConcurrentDictionary<string, string> LocalStrings = new ConcurrentDictionary<string, string>(); + /// <summary> + /// The _instance + /// </summary> + private static LocalizedStrings _instance; + + /// <summary> + /// Gets the instance. + /// </summary> + /// <value>The instance.</value> + public static LocalizedStrings Instance { get { return _instance ?? (_instance = new LocalizedStrings()); } } + + /// <summary> + /// Initializes a new instance of the <see cref="LocalizedStrings" /> class. + /// </summary> + public LocalizedStrings() + { + foreach (var stringObject in Kernel.Instance.StringFiles) + { + AddStringData(LoadFromFile(GetFileName(stringObject),stringObject.GetType())); + } + } + + /// <summary> + /// Gets the name of the file. + /// </summary> + /// <param name="stringObject">The string object.</param> + /// <returns>System.String.</returns> + protected string GetFileName(LocalizedStringData stringObject) + { + var path = Kernel.Instance.ApplicationPaths.LocalizationPath; + var name = Path.Combine(path, stringObject.Prefix + "strings-" + CultureInfo.CurrentCulture + ".xml"); + if (File.Exists(name)) + { + return name; + } + + name = Path.Combine(path, stringObject.Prefix + "strings-" + CultureInfo.CurrentCulture.Parent + ".xml"); + if (File.Exists(name)) + { + return name; + } + + //just return default + return Path.Combine(path, stringObject.Prefix + "strings-en.xml"); + } + + /// <summary> + /// Loads from file. + /// </summary> + /// <param name="file">The file.</param> + /// <param name="t">The t.</param> + /// <returns>LocalizedStringData.</returns> + protected LocalizedStringData LoadFromFile(string file, Type t) + { + var xs = new XmlSerializer(t); + var strings = (LocalizedStringData)Activator.CreateInstance(t); + strings.FileName = file; + Logger.LogInfo("Using String Data from {0}", file); + if (File.Exists(file)) + { + using (var fs = new FileStream(file, FileMode.Open, FileAccess.Read)) + { + strings = (LocalizedStringData)xs.Deserialize(fs); + } + } + else + { + strings.Save(); //brand new - save it + } + + if (strings.ThisVersion != strings.Version && file.ToLower().Contains("-en.xml")) + { + //only re-save the english version as that is the one defined internally + strings = new BaseStrings {FileName = file}; + strings.Save(); + } + return strings; + + } + + /// <summary> + /// Adds the string data. + /// </summary> + /// <param name="stringData">The string data.</param> + public void AddStringData(object stringData ) + { + //translate our object definition into a dictionary for lookups + // and a reverse dictionary so we can lookup keys by value + foreach (var field in stringData.GetType().GetFields().Where(f => f != null && f.FieldType == typeof(string))) + { + string value; + + try + { + value = field.GetValue(stringData) as string; + } + catch (TargetException ex) + { + Logger.LogException("Error getting value for field: {0}", ex, field.Name); + continue; + } + catch (FieldAccessException ex) + { + Logger.LogException("Error getting value for field: {0}", ex, field.Name); + continue; + } + catch (NotSupportedException ex) + { + Logger.LogException("Error getting value for field: {0}", ex, field.Name); + continue; + } + + LocalStrings.TryAdd(field.Name, value); + } + } + + /// <summary> + /// Gets the string. + /// </summary> + /// <param name="key">The key.</param> + /// <returns>System.String.</returns> + public string GetString(string key) + { + string value; + + LocalStrings.TryGetValue(key, out value); + return value; + } + } +} diff --git a/MediaBrowser.Controller/Localization/NLRatingsDictionary.cs b/MediaBrowser.Controller/Localization/NLRatingsDictionary.cs new file mode 100644 index 000000000..7a20f50ba --- /dev/null +++ b/MediaBrowser.Controller/Localization/NLRatingsDictionary.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; + +namespace MediaBrowser.Controller.Localization +{ + /// <summary> + /// Class NLRatingsDictionary + /// </summary> + public class NLRatingsDictionary : Dictionary<string, int> + { + /// <summary> + /// Initializes a new instance of the <see cref="NLRatingsDictionary" /> class. + /// </summary> + public NLRatingsDictionary() + { + Add("NL-AL", 1); + Add("NL-MG6", 2); + Add("NL-6", 3); + Add("NL-9", 5); + Add("NL-12", 6); + Add("NL-16", 8); + } + } +} diff --git a/MediaBrowser.Controller/Localization/Ratings.cs b/MediaBrowser.Controller/Localization/Ratings.cs new file mode 100644 index 000000000..946e25f53 --- /dev/null +++ b/MediaBrowser.Controller/Localization/Ratings.cs @@ -0,0 +1,162 @@ +using MediaBrowser.Common.Extensions; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace MediaBrowser.Controller.Localization +{ + /// <summary> + /// Class Ratings + /// </summary> + public static class Ratings + { + /// <summary> + /// The ratings def + /// </summary> + private static RatingsDefinition ratingsDef; + /// <summary> + /// The _ratings dict + /// </summary> + private static Dictionary<string, int> _ratingsDict; + /// <summary> + /// Gets the ratings dict. + /// </summary> + /// <value>The ratings dict.</value> + public static Dictionary<string, int> RatingsDict + { + get { return _ratingsDict ?? (_ratingsDict = Initialize(false)); } + } + /// <summary> + /// The ratings strings + /// </summary> + private static readonly Dictionary<int, string> ratingsStrings = new Dictionary<int, string>(); + + /// <summary> + /// Initializes the specified block unrated. + /// </summary> + /// <param name="blockUnrated">if set to <c>true</c> [block unrated].</param> + /// <returns>Dictionary{System.StringSystem.Int32}.</returns> + public static Dictionary<string, int> Initialize(bool blockUnrated) + { + //build our ratings dictionary from the combined local one and us one + ratingsDef = new RatingsDefinition(Path.Combine(Kernel.Instance.ApplicationPaths.LocalizationPath, "Ratings-" + Kernel.Instance.Configuration.MetadataCountryCode+".txt")); + //global value of None + var dict = new Dictionary<string, int> {{"None", -1}}; + foreach (var pair in ratingsDef.RatingsDict) + { + dict.TryAdd(pair.Key, pair.Value); + } + if (Kernel.Instance.Configuration.MetadataCountryCode.ToUpper() != "US") + { + foreach (var pair in new USRatingsDictionary()) + { + dict.TryAdd(pair.Key, pair.Value); + } + } + //global values of CS + dict.TryAdd("CS", 1000); + + dict.TryAdd("", blockUnrated ? 1000 : 0); + + //and rating reverse lookup dictionary (non-redundant ones) + ratingsStrings.Clear(); + var lastLevel = -10; + ratingsStrings.Add(-1,LocalizedStrings.Instance.GetString("Any")); + foreach (var pair in ratingsDef.RatingsDict.OrderBy(p => p.Value)) + { + if (pair.Value > lastLevel) + { + lastLevel = pair.Value; + ratingsStrings.TryAdd(pair.Value, pair.Key); + } + } + + ratingsStrings.TryAdd(999, "CS"); + + return dict; + } + + /// <summary> + /// Switches the unrated. + /// </summary> + /// <param name="block">if set to <c>true</c> [block].</param> + public static void SwitchUnrated(bool block) + { + RatingsDict.Remove(""); + RatingsDict.Add("", block ? 1000 : 0); + } + + /// <summary> + /// Levels the specified rating STR. + /// </summary> + /// <param name="ratingStr">The rating STR.</param> + /// <returns>System.Int32.</returns> + public static int Level(string ratingStr) + { + if (ratingStr == null) ratingStr = ""; + if (RatingsDict.ContainsKey(ratingStr)) + return RatingsDict[ratingStr]; + + string stripped = StripCountry(ratingStr); + if (RatingsDict.ContainsKey(stripped)) + return RatingsDict[stripped]; + + return RatingsDict[""]; //return "unknown" level + } + + /// <summary> + /// Strips the country. + /// </summary> + /// <param name="rating">The rating.</param> + /// <returns>System.String.</returns> + private static string StripCountry(string rating) + { + int start = rating.IndexOf('-'); + return start > 0 ? rating.Substring(start + 1) : rating; + } + + /// <summary> + /// Returns a <see cref="System.String" /> that represents this instance. + /// </summary> + /// <param name="level">The level.</param> + /// <returns>A <see cref="System.String" /> that represents this instance.</returns> + public static string ToString(int level) + { + //return the closest one + while (level > 0) + { + if (ratingsStrings.ContainsKey(level)) + return ratingsStrings[level]; + + level--; + } + return ratingsStrings.Values.FirstOrDefault(); //default to first one + } + /// <summary> + /// To the strings. + /// </summary> + /// <returns>List{System.String}.</returns> + public static List<string> ToStrings() + { + //return the whole list of ratings strings + return ratingsStrings.Values.ToList(); + } + + /// <summary> + /// To the values. + /// </summary> + /// <returns>List{System.Int32}.</returns> + public static List<int> ToValues() + { + //return the whole list of ratings values + return ratingsStrings.Keys.ToList(); + } + + //public Microsoft.MediaCenter.UI.Image RatingImage(string rating) + //{ + // return Helper.GetMediaInfoImage("Rated_" + rating); + //} + + + } +} diff --git a/MediaBrowser.Controller/Localization/RatingsDefinition.cs b/MediaBrowser.Controller/Localization/RatingsDefinition.cs new file mode 100644 index 000000000..65bd3bcbb --- /dev/null +++ b/MediaBrowser.Controller/Localization/RatingsDefinition.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections.Generic; +using System.IO; +using MediaBrowser.Common.Logging; + +namespace MediaBrowser.Controller.Localization +{ + /// <summary> + /// Class RatingsDefinition + /// </summary> + public class RatingsDefinition + { + /// <summary> + /// Initializes a new instance of the <see cref="RatingsDefinition" /> class. + /// </summary> + /// <param name="file">The file.</param> + public RatingsDefinition(string file) + { + Logger.LogInfo("Loading Certification Ratings from file " + file); + this.file = file; + if (!Load()) + { + Init(Kernel.Instance.Configuration.MetadataCountryCode.ToUpper()); + } + } + + /// <summary> + /// Inits the specified country. + /// </summary> + /// <param name="country">The country.</param> + protected void Init(string country) + { + //intitialze based on country + switch (country) + { + case "US": + RatingsDict = new USRatingsDictionary(); + break; + case "GB": + RatingsDict = new GBRatingsDictionary(); + break; + case "NL": + RatingsDict = new NLRatingsDictionary(); + break; + case "AU": + RatingsDict = new AURatingsDictionary(); + break; + default: + RatingsDict = new USRatingsDictionary(); + break; + } + Save(); + } + + /// <summary> + /// The file + /// </summary> + readonly string file; + + /// <summary> + /// Save to file + /// </summary> + public void Save() + { + // Use simple text serialization - no need for xml + using (var fs = new StreamWriter(file)) + { + foreach (var pair in RatingsDict) + { + fs.WriteLine(pair.Key + "," + pair.Value); + } + } + } + + /// <summary> + /// Load from file + /// </summary> + /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> + protected bool Load() + { + // Read back in our simple serialized format + RatingsDict = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase); + try + { + using (var fs = new StreamReader(file)) + { + while (!fs.EndOfStream) + { + var line = fs.ReadLine() ?? ""; + var values = line.Split(','); + if (values.Length == 2) + { + + int value; + + if (int.TryParse(values[1], out value)) + { + RatingsDict[values[0].Trim()] = value; + } + else + { + Logger.LogError("Invalid line in ratings file " + file + "(" + line + ")"); + } + } + } + } + } + catch + { + // Couldn't load - probably just not there yet + return false; + } + return true; + } + + /// <summary> + /// The ratings dict + /// </summary> + public Dictionary<string, int> RatingsDict = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase); + + } +} diff --git a/MediaBrowser.Controller/Localization/USRatingsDictionary.cs b/MediaBrowser.Controller/Localization/USRatingsDictionary.cs new file mode 100644 index 000000000..2c7a69841 --- /dev/null +++ b/MediaBrowser.Controller/Localization/USRatingsDictionary.cs @@ -0,0 +1,39 @@ +using System.Collections.Generic; + +namespace MediaBrowser.Controller.Localization +{ + /// <summary> + /// Class USRatingsDictionary + /// </summary> + public class USRatingsDictionary : Dictionary<string,int> + { + /// <summary> + /// Initializes a new instance of the <see cref="USRatingsDictionary" /> class. + /// </summary> + public USRatingsDictionary() + { + Add("G", 1); + Add("E", 1); + Add("EC", 1); + Add("TV-G", 1); + Add("TV-Y", 2); + Add("TV-Y7", 3); + Add("TV-Y7-FV", 4); + Add("PG", 5); + Add("TV-PG", 5); + Add("PG-13", 7); + Add("T", 7); + Add("TV-14", 8); + Add("R", 9); + Add("M", 9); + Add("TV-MA", 9); + Add("NC-17", 10); + Add("AO", 15); + Add("RP", 15); + Add("UR", 15); + Add("NR", 15); + Add("X", 15); + Add("XXX", 100); + } + } +} |
