diff options
author | sr55 <[email protected]> | 2013-05-29 17:31:58 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2013-05-29 17:31:58 +0000 |
commit | bffc8a4ab97bcd4630496c62be4720e0c590f1fa (patch) | |
tree | de2a7bac1438c0dbec660388fee636053ef3a96b /win | |
parent | e0c83de39ee1c7533842c566b4cbea80c0257f99 (diff) |
WinGui: Use ISO639-2 Codes rather than language names for auto language selection
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5524 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win')
4 files changed, 71 insertions, 9 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Parsing/Subtitle.cs b/win/CS/HandBrake.ApplicationServices/Parsing/Subtitle.cs index 34a919908..0a68476f4 100644 --- a/win/CS/HandBrake.ApplicationServices/Parsing/Subtitle.cs +++ b/win/CS/HandBrake.ApplicationServices/Parsing/Subtitle.cs @@ -69,6 +69,22 @@ namespace HandBrake.ApplicationServices.Parsing public string LanguageCode { get; set; }
/// <summary>
+ /// Gets the language code clean.
+ /// TODO Remove this after fixing language code.
+ /// </summary>
+ public string LanguageCodeClean
+ {
+ get
+ {
+ if (this.LanguageCode != null)
+ {
+ return this.LanguageCode.Replace("iso639-2: ", string.Empty).Trim();
+ }
+ return string.Empty;
+ }
+ }
+
+ /// <summary>
/// Gets or sets the Subtitle Type
/// </summary>
public SubtitleType SubtitleType { get; set; }
diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/LanguageUtilities.cs b/win/CS/HandBrake.ApplicationServices/Utilities/LanguageUtilities.cs index 833c6d989..bbfe8f62c 100644 --- a/win/CS/HandBrake.ApplicationServices/Utilities/LanguageUtilities.cs +++ b/win/CS/HandBrake.ApplicationServices/Utilities/LanguageUtilities.cs @@ -10,6 +10,7 @@ namespace HandBrake.ApplicationServices.Utilities
{
using System.Collections.Generic;
+ using System.Collections.Specialized;
/// <summary>
/// Language Utilities
@@ -17,12 +18,22 @@ namespace HandBrake.ApplicationServices.Utilities public class LanguageUtilities
{
/// <summary>
+ /// The language map.
+ /// </summary>
+ private static IDictionary<string, string> languageMap;
+
+ /// <summary>
/// Map languages and their iso639_2 value into a IDictionary
/// </summary>
/// <returns>A Dictionary containing the language and iso code</returns>
public static IDictionary<string, string> MapLanguages()
{
- IDictionary<string, string> languageMap = new Dictionary<string, string>
+ if (languageMap != null)
+ {
+ return languageMap;
+ }
+
+ languageMap = new Dictionary<string, string>
{
{"(Any)", "und"},
{"Afar", "aar"},
@@ -213,5 +224,30 @@ namespace HandBrake.ApplicationServices.Utilities };
return languageMap;
}
+
+ /// <summary>
+ /// The get language codes.
+ /// </summary>
+ /// <param name="userLanguages">
+ /// The user languages.
+ /// </param>
+ /// <returns>
+ /// The <see cref="IList"/>.
+ /// </returns>
+ public static List<string> GetLanguageCodes(StringCollection userLanguages)
+ {
+ // Translate to Iso Codes
+ List<string> iso6392Codes = new List<string>();
+ foreach (var item in userLanguages)
+ {
+ string isoCode;
+ if (LanguageUtilities.MapLanguages().TryGetValue(item, out isoCode))
+ {
+ iso6392Codes.Add(isoCode);
+ }
+ }
+
+ return iso6392Codes;
+ }
}
}
diff --git a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs index 2146b1c6c..ee9b09f31 100644 --- a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs @@ -38,6 +38,9 @@ namespace HandBrakeWPF.ViewModels /// </summary>
private IEnumerable<Audio> sourceTracks;
+ /// <summary>
+ /// The current preset.
+ /// </summary>
private Preset currentPreset;
#region Constructors and Destructors
@@ -414,9 +417,15 @@ namespace HandBrakeWPF.ViewModels private IEnumerable<Audio> GetSelectedLanguagesTracks()
{
List<Audio> trackList = new List<Audio>();
- foreach (string language in this.UserSettingService.GetUserSetting<StringCollection>(UserSettingConstants.SelectedLanguages))
+
+
+ List<string> isoCodes =
+ LanguageUtilities.GetLanguageCodes(
+ this.UserSettingService.GetUserSetting<StringCollection>(UserSettingConstants.SelectedLanguages));
+
+ foreach (string code in isoCodes)
{
- trackList.AddRange(this.SourceTracks.Where(source => source.Language.Trim() == language));
+ trackList.AddRange(this.SourceTracks.Where(source => source.LanguageCode.Trim() == code));
}
return trackList;
diff --git a/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs index 90dae495f..feabc08f3 100644 --- a/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs @@ -113,7 +113,6 @@ namespace HandBrakeWPF.ViewModels /// </summary>
public void AddAllClosedCaptions()
{
-
foreach (Subtitle subtitle in this.SourceTitlesSubset(null).Where(s => s.SubtitleType == SubtitleType.CC))
{
this.Add(subtitle);
@@ -137,12 +136,14 @@ namespace HandBrakeWPF.ViewModels public void AddAllRemainingForSelectedLanguages()
{
// Get a list of subtitle tracks that match the users lanaguages
- StringCollection userSelectedLanguages =
- this.UserSettingService.GetUserSetting<StringCollection>(UserSettingConstants.SelectedLanguages);
- userSelectedLanguages.Add(
- this.UserSettingService.GetUserSetting<string>(UserSettingConstants.NativeLanguageForSubtitles));
+ StringCollection userSelectedLanguages = this.UserSettingService.GetUserSetting<StringCollection>(UserSettingConstants.SelectedLanguages);
+ userSelectedLanguages.Add(this.UserSettingService.GetUserSetting<string>(UserSettingConstants.NativeLanguageForSubtitles));
+
+ // Translate to Iso Codes
+ List<string> iso6392Codes = LanguageUtilities.GetLanguageCodes(userSelectedLanguages);
+
List<Subtitle> availableTracks =
- this.SourceTracks.Where(subtitle => userSelectedLanguages.Contains(subtitle.Language)).ToList();
+ this.SourceTracks.Where(subtitle => iso6392Codes.Contains(subtitle.LanguageCodeClean)).ToList();
foreach (Subtitle subtitle in this.SourceTitlesSubset(availableTracks))
{
|