parent
cad4f3740b
commit
8c10f8b55c
@ -1,48 +0,0 @@
|
||||
import createFetchHandler from 'Store/Actions/Creators/createFetchHandler';
|
||||
import { createThunk } from 'Store/thunks';
|
||||
|
||||
//
|
||||
// Variables
|
||||
|
||||
const section = 'settings.languages';
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_LANGUAGES = 'settings/languages/fetchLanguages';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchLanguages = createThunk(FETCH_LANGUAGES);
|
||||
|
||||
//
|
||||
// Details
|
||||
|
||||
export default {
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
defaultState: {
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: null,
|
||||
items: []
|
||||
},
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
|
||||
actionHandlers: {
|
||||
[FETCH_LANGUAGES]: createFetchHandler(section, '/language')
|
||||
},
|
||||
|
||||
//
|
||||
// Reducers
|
||||
|
||||
reducers: {
|
||||
|
||||
}
|
||||
|
||||
};
|
@ -0,0 +1,39 @@
|
||||
import createFetchHandler from 'Store/Actions/Creators/createFetchHandler';
|
||||
import { createThunk, handleThunks } from 'Store/thunks';
|
||||
import createHandleActions from './Creators/createHandleActions';
|
||||
|
||||
//
|
||||
// Variables
|
||||
|
||||
export const section = 'localization';
|
||||
|
||||
//
|
||||
// State
|
||||
|
||||
export const defaultState = {
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: null,
|
||||
items: []
|
||||
};
|
||||
|
||||
//
|
||||
// Actions Types
|
||||
|
||||
export const FETCH_LOCALIZATION_OPTIONS = 'localization/fetchLocalizationOptions';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
export const fetchLocalizationOptions = createThunk(FETCH_LOCALIZATION_OPTIONS);
|
||||
|
||||
//
|
||||
// Action Handlers
|
||||
export const actionHandlers = handleThunks({
|
||||
|
||||
[FETCH_LOCALIZATION_OPTIONS]: createFetchHandler(section, '/localization/options')
|
||||
});
|
||||
|
||||
//
|
||||
// Reducers
|
||||
export const reducers = createHandleActions({}, defaultState, section);
|
@ -1,85 +0,0 @@
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Languages;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.Languages
|
||||
{
|
||||
[TestFixture]
|
||||
public class LanguageFixture : CoreTest
|
||||
{
|
||||
public static object[] FromIntCases =
|
||||
{
|
||||
new object[] { 1, Language.English },
|
||||
new object[] { 2, Language.French },
|
||||
new object[] { 3, Language.Spanish },
|
||||
new object[] { 4, Language.German },
|
||||
new object[] { 5, Language.Italian },
|
||||
new object[] { 6, Language.Danish },
|
||||
new object[] { 7, Language.Dutch },
|
||||
new object[] { 8, Language.Japanese },
|
||||
new object[] { 9, Language.Icelandic },
|
||||
new object[] { 10, Language.Chinese },
|
||||
new object[] { 11, Language.Russian },
|
||||
new object[] { 12, Language.Polish },
|
||||
new object[] { 13, Language.Vietnamese },
|
||||
new object[] { 14, Language.Swedish },
|
||||
new object[] { 15, Language.Norwegian },
|
||||
new object[] { 16, Language.Finnish },
|
||||
new object[] { 17, Language.Turkish },
|
||||
new object[] { 18, Language.Portuguese },
|
||||
new object[] { 19, Language.Flemish },
|
||||
new object[] { 20, Language.Greek },
|
||||
new object[] { 21, Language.Korean },
|
||||
new object[] { 22, Language.Hungarian },
|
||||
new object[] { 23, Language.Hebrew },
|
||||
new object[] { 24, Language.Lithuanian },
|
||||
new object[] { 25, Language.Czech }
|
||||
};
|
||||
|
||||
public static object[] ToIntCases =
|
||||
{
|
||||
new object[] { Language.English, 1 },
|
||||
new object[] { Language.French, 2 },
|
||||
new object[] { Language.Spanish, 3 },
|
||||
new object[] { Language.German, 4 },
|
||||
new object[] { Language.Italian, 5 },
|
||||
new object[] { Language.Danish, 6 },
|
||||
new object[] { Language.Dutch, 7 },
|
||||
new object[] { Language.Japanese, 8 },
|
||||
new object[] { Language.Icelandic, 9 },
|
||||
new object[] { Language.Chinese, 10 },
|
||||
new object[] { Language.Russian, 11 },
|
||||
new object[] { Language.Polish, 12 },
|
||||
new object[] { Language.Vietnamese, 13 },
|
||||
new object[] { Language.Swedish, 14 },
|
||||
new object[] { Language.Norwegian, 15 },
|
||||
new object[] { Language.Finnish, 16 },
|
||||
new object[] { Language.Turkish, 17 },
|
||||
new object[] { Language.Portuguese, 18 },
|
||||
new object[] { Language.Flemish, 19 },
|
||||
new object[] { Language.Greek, 20 },
|
||||
new object[] { Language.Korean, 21 },
|
||||
new object[] { Language.Hungarian, 22 },
|
||||
new object[] { Language.Hebrew, 23 },
|
||||
new object[] { Language.Lithuanian, 24 },
|
||||
new object[] { Language.Czech, 25 }
|
||||
};
|
||||
|
||||
[Test]
|
||||
[TestCaseSource("FromIntCases")]
|
||||
public void should_be_able_to_convert_int_to_languageTypes(int source, Language expected)
|
||||
{
|
||||
var language = (Language)source;
|
||||
language.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCaseSource("ToIntCases")]
|
||||
public void should_be_able_to_convert_languageTypes_to_int(Language source, int expected)
|
||||
{
|
||||
var i = (int)source;
|
||||
i.Should().Be(expected);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using FluentMigrator;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration
|
||||
{
|
||||
[Migration(021)]
|
||||
public class localization_setting_to_string : NzbDroneMigrationBase
|
||||
{
|
||||
protected override void MainDbUpgrade()
|
||||
{
|
||||
Execute.WithConnection(FixLocalizationConfig);
|
||||
}
|
||||
|
||||
private void FixLocalizationConfig(IDbConnection conn, IDbTransaction tran)
|
||||
{
|
||||
string uiLanguage;
|
||||
string uiCulture;
|
||||
|
||||
using (var cmd = conn.CreateCommand())
|
||||
{
|
||||
cmd.Transaction = tran;
|
||||
cmd.CommandText = "SELECT \"Value\" FROM \"Config\" WHERE \"Key\" = 'uilanguage'";
|
||||
|
||||
uiLanguage = (string)cmd.ExecuteScalar();
|
||||
}
|
||||
|
||||
if (uiLanguage != null && int.TryParse(uiLanguage, out var uiLanguageInt))
|
||||
{
|
||||
uiCulture = _uiMapping.GetValueOrDefault(uiLanguageInt) ?? "en";
|
||||
|
||||
using (var insertCmd = conn.CreateCommand())
|
||||
{
|
||||
insertCmd.Transaction = tran;
|
||||
insertCmd.CommandText = string.Format("UPDATE \"Config\" SET \"Value\" = '{0}' WHERE \"Key\" = 'uilanguage'", uiCulture);
|
||||
insertCmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Dictionary<int, string> _uiMapping = new Dictionary<int, string>()
|
||||
{
|
||||
{ 1, "en" },
|
||||
{ 2, "fr" },
|
||||
{ 3, "es" },
|
||||
{ 4, "de" },
|
||||
{ 5, "it" },
|
||||
{ 6, "da" },
|
||||
{ 7, "nl" },
|
||||
{ 8, "ja" },
|
||||
{ 9, "is" },
|
||||
{ 10, "zh_CN" },
|
||||
{ 11, "ru" },
|
||||
{ 12, "pl" },
|
||||
{ 13, "vi" },
|
||||
{ 14, "sv" },
|
||||
{ 15, "nb_NO" },
|
||||
{ 16, "fi" },
|
||||
{ 17, "tr" },
|
||||
{ 18, "pt" },
|
||||
{ 19, "en" },
|
||||
{ 20, "el" },
|
||||
{ 21, "ko" },
|
||||
{ 22, "hu" },
|
||||
{ 23, "he" },
|
||||
{ 24, "lt" },
|
||||
{ 25, "cs" },
|
||||
{ 26, "hi" },
|
||||
{ 27, "ro" },
|
||||
{ 28, "th" },
|
||||
{ 29, "bg" },
|
||||
{ 30, "pt_BR" },
|
||||
{ 31, "ar" },
|
||||
{ 32, "uk" },
|
||||
{ 33, "fa" },
|
||||
{ 34, "be" },
|
||||
{ 35, "zh_TW" },
|
||||
};
|
||||
}
|
||||
}
|
@ -1,193 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Datastore;
|
||||
|
||||
namespace NzbDrone.Core.Languages
|
||||
{
|
||||
public class Language : IEmbeddedDocument, IEquatable<Language>
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public Language()
|
||||
{
|
||||
}
|
||||
|
||||
private Language(int id, string name)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Id.GetHashCode();
|
||||
}
|
||||
|
||||
public bool Equals(Language other)
|
||||
{
|
||||
if (ReferenceEquals(null, other))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ReferenceEquals(this, other))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return Id.Equals(other.Id);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ReferenceEquals(this, obj))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return Equals(obj as Language);
|
||||
}
|
||||
|
||||
public static bool operator ==(Language left, Language right)
|
||||
{
|
||||
return Equals(left, right);
|
||||
}
|
||||
|
||||
public static bool operator !=(Language left, Language right)
|
||||
{
|
||||
return !Equals(left, right);
|
||||
}
|
||||
|
||||
public static Language Unknown => new Language(0, "Unknown");
|
||||
public static Language English => new Language(1, "English");
|
||||
public static Language French => new Language(2, "French");
|
||||
public static Language Spanish => new Language(3, "Spanish");
|
||||
public static Language German => new Language(4, "German");
|
||||
public static Language Italian => new Language(5, "Italian");
|
||||
public static Language Danish => new Language(6, "Danish");
|
||||
public static Language Dutch => new Language(7, "Dutch");
|
||||
public static Language Japanese => new Language(8, "Japanese");
|
||||
public static Language Icelandic => new Language(9, "Icelandic");
|
||||
public static Language Chinese => new Language(10, "Chinese (Simplified)");
|
||||
public static Language Russian => new Language(11, "Russian");
|
||||
public static Language Polish => new Language(12, "Polish");
|
||||
public static Language Vietnamese => new Language(13, "Vietnamese");
|
||||
public static Language Swedish => new Language(14, "Swedish");
|
||||
public static Language Norwegian => new Language(15, "Norwegian");
|
||||
public static Language Finnish => new Language(16, "Finnish");
|
||||
public static Language Turkish => new Language(17, "Turkish");
|
||||
public static Language Portuguese => new Language(18, "Portuguese");
|
||||
public static Language Flemish => new Language(19, "Flemish");
|
||||
public static Language Greek => new Language(20, "Greek");
|
||||
public static Language Korean => new Language(21, "Korean");
|
||||
public static Language Hungarian => new Language(22, "Hungarian");
|
||||
public static Language Hebrew => new Language(23, "Hebrew");
|
||||
public static Language Lithuanian => new Language(24, "Lithuanian");
|
||||
public static Language Czech => new Language(25, "Czech");
|
||||
public static Language Hindi => new Language(26, "Hindi");
|
||||
public static Language Romanian => new Language(27, "Romanian");
|
||||
public static Language Thai => new Language(28, "Thai");
|
||||
public static Language Bulgarian => new Language(29, "Bulgarian");
|
||||
public static Language PortugueseBR => new Language(30, "Portuguese (Brazil)");
|
||||
public static Language Arabic => new Language(31, "Arabic");
|
||||
public static Language Ukrainian => new Language(32, "Ukrainian");
|
||||
public static Language Persian => new Language(33, "Persian");
|
||||
public static Language Bengali => new Language(34, "Bengali");
|
||||
public static Language ChineseTW => new Language(35, "Chinese (Traditional)");
|
||||
public static Language Any => new Language(-1, "Any");
|
||||
public static Language Original => new Language(-2, "Original");
|
||||
|
||||
public static List<Language> All
|
||||
{
|
||||
get
|
||||
{
|
||||
return new List<Language>
|
||||
{
|
||||
Unknown,
|
||||
English,
|
||||
French,
|
||||
Spanish,
|
||||
German,
|
||||
Italian,
|
||||
Danish,
|
||||
Dutch,
|
||||
Japanese,
|
||||
Icelandic,
|
||||
Chinese,
|
||||
Russian,
|
||||
Polish,
|
||||
Vietnamese,
|
||||
Swedish,
|
||||
Norwegian,
|
||||
Finnish,
|
||||
Turkish,
|
||||
Portuguese,
|
||||
Flemish,
|
||||
Greek,
|
||||
Korean,
|
||||
Hungarian,
|
||||
Hebrew,
|
||||
Lithuanian,
|
||||
Czech,
|
||||
Romanian,
|
||||
Hindi,
|
||||
Thai,
|
||||
Bulgarian,
|
||||
Any,
|
||||
Original
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static Language FindById(int id)
|
||||
{
|
||||
if (id == 0)
|
||||
{
|
||||
return Unknown;
|
||||
}
|
||||
|
||||
Language language = All.FirstOrDefault(v => v.Id == id);
|
||||
|
||||
if (language == null)
|
||||
{
|
||||
throw new ArgumentException("ID does not match a known language", nameof(id));
|
||||
}
|
||||
|
||||
return language;
|
||||
}
|
||||
|
||||
public static explicit operator Language(int id)
|
||||
{
|
||||
return FindById(id);
|
||||
}
|
||||
|
||||
public static explicit operator int(Language language)
|
||||
{
|
||||
return language.Id;
|
||||
}
|
||||
|
||||
public static explicit operator Language(string lang)
|
||||
{
|
||||
var language = All.FirstOrDefault(v => v.Name.Equals(lang, StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
if (language == null)
|
||||
{
|
||||
throw new ArgumentException("Language does not match a known language", nameof(lang));
|
||||
}
|
||||
|
||||
return language;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace NzbDrone.Core.Languages
|
||||
{
|
||||
public static class LanguageExtensions
|
||||
{
|
||||
public static string ToExtendedString(this IEnumerable<Language> languages)
|
||||
{
|
||||
return string.Join(", ", languages.Select(l => l.ToString()));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.Annotations;
|
||||
|
||||
namespace NzbDrone.Core.Languages
|
||||
{
|
||||
public class LanguageFieldConverter : ISelectOptionsConverter
|
||||
{
|
||||
public List<SelectOption> GetSelectOptions()
|
||||
{
|
||||
return Language.All.ConvertAll(v => new SelectOption { Value = v.Id, Name = v.Name });
|
||||
}
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace NzbDrone.Core.Languages
|
||||
{
|
||||
public class LanguagesComparer : IComparer<List<Language>>
|
||||
{
|
||||
public int Compare(List<Language> x, List<Language> y)
|
||||
{
|
||||
if (!x.Any() && !y.Any())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!x.Any() && y.Any())
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (x.Any() && !y.Any())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (x.Count > 1 && y.Count > 1 && x.Count > y.Count)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (x.Count > 1 && y.Count > 1 && x.Count < y.Count)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (x.Count > 1 && y.Count == 1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (x.Count == 1 && y.Count > 1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (x.Count == 1 && y.Count == 1)
|
||||
{
|
||||
return x.First().Name.CompareTo(y.First().Name);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Annotations;
|
||||
|
||||
namespace NzbDrone.Core.Languages
|
||||
{
|
||||
public class RealLanguageFieldConverter : ISelectOptionsConverter
|
||||
{
|
||||
public List<SelectOption> GetSelectOptions()
|
||||
{
|
||||
return Language.All
|
||||
.Where(l => l != Language.Unknown && l != Language.Any)
|
||||
.ToList()
|
||||
.ConvertAll(v => new SelectOption { Value = v.Id, Name = v.Name });
|
||||
}
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
using NzbDrone.Core.Languages;
|
||||
|
||||
namespace NzbDrone.Core.Parser
|
||||
{
|
||||
public class IsoLanguage
|
||||
{
|
||||
public string TwoLetterCode { get; set; }
|
||||
public string ThreeLetterCode { get; set; }
|
||||
public string CountryCode { get; set; }
|
||||
public string EnglishName { get; set; }
|
||||
public Language Language { get; set; }
|
||||
|
||||
public IsoLanguage(string twoLetterCode, string countryCode, string threeLetterCode, string englishName, Language language)
|
||||
{
|
||||
TwoLetterCode = twoLetterCode;
|
||||
ThreeLetterCode = threeLetterCode;
|
||||
CountryCode = countryCode;
|
||||
EnglishName = englishName;
|
||||
Language = language;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Languages;
|
||||
|
||||
namespace NzbDrone.Core.Parser
|
||||
{
|
||||
public static class IsoLanguages
|
||||
{
|
||||
private static readonly HashSet<IsoLanguage> All = new HashSet<IsoLanguage>
|
||||
{
|
||||
new IsoLanguage("en", "", "eng", "English", Language.English),
|
||||
new IsoLanguage("fr", "fr", "fra", "French", Language.French),
|
||||
new IsoLanguage("es", "", "spa", "Spanish", Language.Spanish),
|
||||
new IsoLanguage("de", "", "deu", "German", Language.German),
|
||||
new IsoLanguage("it", "", "ita", "Italian", Language.Italian),
|
||||
new IsoLanguage("da", "", "dan", "Danish", Language.Danish),
|
||||
new IsoLanguage("nl", "", "nld", "Dutch", Language.Dutch),
|
||||
new IsoLanguage("ja", "", "jpn", "Japanese", Language.Japanese),
|
||||
new IsoLanguage("is", "", "isl", "Icelandic", Language.Icelandic),
|
||||
new IsoLanguage("zh", "cn", "zho", "Chinese (Simplified)", Language.Chinese),
|
||||
new IsoLanguage("zh", "tw", "zho", "Chinese (Traditional)", Language.ChineseTW),
|
||||
new IsoLanguage("ru", "", "rus", "Russian", Language.Russian),
|
||||
new IsoLanguage("pl", "", "pol", "Polish", Language.Polish),
|
||||
new IsoLanguage("vi", "", "vie", "Vietnamese", Language.Vietnamese),
|
||||
new IsoLanguage("sv", "", "swe", "Swedish", Language.Swedish),
|
||||
new IsoLanguage("no", "", "nor", "Norwegian", Language.Norwegian),
|
||||
new IsoLanguage("nb", "", "nob", "Norwegian Bokmal", Language.Norwegian),
|
||||
new IsoLanguage("fi", "", "fin", "Finnish", Language.Finnish),
|
||||
new IsoLanguage("tr", "", "tur", "Turkish", Language.Turkish),
|
||||
new IsoLanguage("pt", "pt", "por", "Portuguese", Language.Portuguese),
|
||||
new IsoLanguage("el", "", "ell", "Greek", Language.Greek),
|
||||
new IsoLanguage("ko", "", "kor", "Korean", Language.Korean),
|
||||
new IsoLanguage("hu", "", "hun", "Hungarian", Language.Hungarian),
|
||||
new IsoLanguage("he", "", "heb", "Hebrew", Language.Hebrew),
|
||||
new IsoLanguage("cs", "", "ces", "Czech", Language.Czech),
|
||||
new IsoLanguage("hi", "", "hin", "Hindi", Language.Hindi),
|
||||
new IsoLanguage("th", "", "tha", "Thai", Language.Thai),
|
||||
new IsoLanguage("bg", "", "bul", "Bulgarian", Language.Bulgarian),
|
||||
new IsoLanguage("ro", "", "ron", "Romanian", Language.Romanian),
|
||||
new IsoLanguage("pt", "br", "", "Portuguese (Brazil)", Language.PortugueseBR),
|
||||
new IsoLanguage("ar", "", "ara", "Arabic", Language.Arabic),
|
||||
new IsoLanguage("uk", "", "ukr", "Ukrainian", Language.Ukrainian),
|
||||
new IsoLanguage("fa", "", "fas", "Persian", Language.Persian),
|
||||
new IsoLanguage("be", "", "ben", "Bengali", Language.Bengali)
|
||||
};
|
||||
|
||||
public static IsoLanguage Find(string isoCode)
|
||||
{
|
||||
var isoArray = isoCode.Split('-');
|
||||
|
||||
var langCode = isoArray[0].ToLower();
|
||||
|
||||
if (langCode.Length == 2)
|
||||
{
|
||||
//Lookup ISO639-1 code
|
||||
var isoLanguages = All.Where(l => l.TwoLetterCode == langCode).ToList();
|
||||
|
||||
if (isoArray.Length > 1)
|
||||
{
|
||||
isoLanguages = isoLanguages.Any(l => l.CountryCode == isoArray[1].ToLower()) ?
|
||||
isoLanguages.Where(l => l.CountryCode == isoArray[1].ToLower()).ToList() : isoLanguages.Where(l => string.IsNullOrEmpty(l.CountryCode)).ToList();
|
||||
}
|
||||
|
||||
return isoLanguages.FirstOrDefault();
|
||||
}
|
||||
else if (langCode.Length == 3)
|
||||
{
|
||||
//Lookup ISO639-2T code
|
||||
return All.FirstOrDefault(l => l.ThreeLetterCode == langCode);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IsoLanguage FindByName(string name)
|
||||
{
|
||||
return All.FirstOrDefault(l => l.EnglishName == name.Trim());
|
||||
}
|
||||
|
||||
public static IsoLanguage Get(Language language)
|
||||
{
|
||||
return All.FirstOrDefault(l => l.Language == language);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,272 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Instrumentation;
|
||||
using NzbDrone.Core.Languages;
|
||||
|
||||
namespace NzbDrone.Core.Parser
|
||||
{
|
||||
public static class LanguageParser
|
||||
{
|
||||
private static readonly Logger Logger = NzbDroneLogger.GetLogger(typeof(LanguageParser));
|
||||
|
||||
private static readonly Regex LanguageRegex = new Regex(@"(?:\W|_|^)(?<italian>\b(?:ita|italian)\b)|(?<german>\b(?:german|videomann|ger)\b)|(?<flemish>flemish)|(?<bulgarian>bgaudio)|(?<greek>greek)|(?<french>(?:\W|_)(?:FR|VO|VFF|VFQ|VFI|VF2|TRUEFRENCH)(?:\W|_))|(?<russian>\brus\b)|(?<english>\beng\b)|(?<hungarian>\b(?:HUNDUB|HUN)\b)|(?<hebrew>\bHebDub\b)|(?<chinese>\[(?:CH[ST]|BIG5|GB)\]|简|繁|字幕)",
|
||||
RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
|
||||
private static readonly Regex CaseSensitiveLanguageRegex = new Regex(@"(?<lithuanian>\bLT\b)|(?<czech>\bCZ\b)",
|
||||
RegexOptions.Compiled);
|
||||
|
||||
private static readonly Regex SubtitleLanguageRegex = new Regex(".+?[-_. ](?<iso_code>[a-z]{2,3})(?:[-_. ]forced)?$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
public static List<Language> ParseLanguages(string title)
|
||||
{
|
||||
var lowerTitle = title.ToLower();
|
||||
var languages = new List<Language>();
|
||||
|
||||
if (lowerTitle.Contains("english"))
|
||||
{
|
||||
languages.Add(Language.English);
|
||||
}
|
||||
|
||||
if (lowerTitle.Contains("french"))
|
||||
{
|
||||
languages.Add(Language.French);
|
||||
}
|
||||
|
||||
if (lowerTitle.Contains("spanish"))
|
||||
{
|
||||
languages.Add(Language.Spanish);
|
||||
}
|
||||
|
||||
if (lowerTitle.Contains("danish"))
|
||||
{
|
||||
languages.Add(Language.Danish);
|
||||
}
|
||||
|
||||
if (lowerTitle.Contains("dutch"))
|
||||
{
|
||||
languages.Add(Language.Dutch);
|
||||
}
|
||||
|
||||
if (lowerTitle.Contains("japanese"))
|
||||
{
|
||||
languages.Add(Language.Japanese);
|
||||
}
|
||||
|
||||
if (lowerTitle.Contains("icelandic"))
|
||||
{
|
||||
languages.Add(Language.Icelandic);
|
||||
}
|
||||
|
||||
if (lowerTitle.Contains("mandarin") || lowerTitle.Contains("cantonese") || lowerTitle.Contains("chinese"))
|
||||
{
|
||||
languages.Add(Language.Chinese);
|
||||
}
|
||||
|
||||
if (lowerTitle.Contains("korean"))
|
||||
{
|
||||
languages.Add(Language.Korean);
|
||||
}
|
||||
|
||||
if (lowerTitle.Contains("russian"))
|
||||
{
|
||||
languages.Add(Language.Russian);
|
||||
}
|
||||
|
||||
if (lowerTitle.Contains("romanian"))
|
||||
{
|
||||
languages.Add(Language.Romanian);
|
||||
}
|
||||
|
||||
if (lowerTitle.Contains("hindi"))
|
||||
{
|
||||
languages.Add(Language.Hindi);
|
||||
}
|
||||
|
||||
if (lowerTitle.Contains("thai"))
|
||||
{
|
||||
languages.Add(Language.Thai);
|
||||
}
|
||||
|
||||
if (lowerTitle.Contains("bulgarian"))
|
||||
{
|
||||
languages.Add(Language.Bulgarian);
|
||||
}
|
||||
|
||||
if (lowerTitle.Contains("polish"))
|
||||
{
|
||||
languages.Add(Language.Polish);
|
||||
}
|
||||
|
||||
if (lowerTitle.Contains("vietnamese"))
|
||||
{
|
||||
languages.Add(Language.Vietnamese);
|
||||
}
|
||||
|
||||
if (lowerTitle.Contains("swedish"))
|
||||
{
|
||||
languages.Add(Language.Swedish);
|
||||
}
|
||||
|
||||
if (lowerTitle.Contains("norwegian"))
|
||||
{
|
||||
languages.Add(Language.Norwegian);
|
||||
}
|
||||
|
||||
if (lowerTitle.Contains("finnish"))
|
||||
{
|
||||
languages.Add(Language.Finnish);
|
||||
}
|
||||
|
||||
if (lowerTitle.Contains("turkish"))
|
||||
{
|
||||
languages.Add(Language.Turkish);
|
||||
}
|
||||
|
||||
if (lowerTitle.Contains("portuguese"))
|
||||
{
|
||||
languages.Add(Language.Portuguese);
|
||||
}
|
||||
|
||||
if (lowerTitle.Contains("hungarian"))
|
||||
{
|
||||
languages.Add(Language.Hungarian);
|
||||
}
|
||||
|
||||
if (lowerTitle.Contains("hebrew"))
|
||||
{
|
||||
languages.Add(Language.Hebrew);
|
||||
}
|
||||
|
||||
// Case sensitive
|
||||
var caseSensitiveMatch = CaseSensitiveLanguageRegex.Match(title);
|
||||
|
||||
if (caseSensitiveMatch.Groups["lithuanian"].Captures.Cast<Capture>().Any())
|
||||
{
|
||||
languages.Add(Language.Lithuanian);
|
||||
}
|
||||
|
||||
if (caseSensitiveMatch.Groups["czech"].Captures.Cast<Capture>().Any())
|
||||
{
|
||||
languages.Add(Language.Czech);
|
||||
}
|
||||
|
||||
var matches = LanguageRegex.Matches(title);
|
||||
|
||||
foreach (Match match in matches)
|
||||
{
|
||||
if (match.Groups["italian"].Captures.Cast<Capture>().Any())
|
||||
{
|
||||
languages.Add(Language.Italian);
|
||||
}
|
||||
|
||||
if (match.Groups["german"].Captures.Cast<Capture>().Any())
|
||||
{
|
||||
languages.Add(Language.German);
|
||||
}
|
||||
|
||||
if (match.Groups["flemish"].Captures.Cast<Capture>().Any())
|
||||
{
|
||||
languages.Add(Language.Flemish);
|
||||
}
|
||||
|
||||
if (match.Groups["greek"].Captures.Cast<Capture>().Any())
|
||||
{
|
||||
languages.Add(Language.Greek);
|
||||
}
|
||||
|
||||
if (match.Groups["french"].Success)
|
||||
{
|
||||
languages.Add(Language.French);
|
||||
}
|
||||
|
||||
if (match.Groups["russian"].Success)
|
||||
{
|
||||
languages.Add(Language.Russian);
|
||||
}
|
||||
|
||||
if (match.Groups["english"].Success)
|
||||
{
|
||||
languages.Add(Language.English);
|
||||
}
|
||||
|
||||
if (match.Groups["bulgarian"].Success)
|
||||
{
|
||||
languages.Add(Language.Bulgarian);
|
||||
}
|
||||
|
||||
if (match.Groups["dutch"].Success)
|
||||
{
|
||||
languages.Add(Language.Dutch);
|
||||
}
|
||||
|
||||
if (match.Groups["hungarian"].Success)
|
||||
{
|
||||
languages.Add(Language.Hungarian);
|
||||
}
|
||||
|
||||
if (match.Groups["hebrew"].Success)
|
||||
{
|
||||
languages.Add(Language.Hebrew);
|
||||
}
|
||||
|
||||
if (match.Groups["chinese"].Success)
|
||||
{
|
||||
languages.Add(Language.Chinese);
|
||||
}
|
||||
}
|
||||
|
||||
if (title.ToLower().Contains("multi"))
|
||||
{
|
||||
//Let's add english language to multi release as a safe guard.
|
||||
if (!languages.Contains(Language.English) && languages.Count < 2)
|
||||
{
|
||||
languages.Add(Language.English);
|
||||
}
|
||||
}
|
||||
|
||||
if (!languages.Any())
|
||||
{
|
||||
languages.Add(Language.Unknown);
|
||||
}
|
||||
|
||||
return languages.DistinctBy(l => (int)l).ToList();
|
||||
}
|
||||
|
||||
public static Language ParseSubtitleLanguage(string fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
#if !LIBRARY
|
||||
Logger.Debug("Parsing language from subtitle file: {0}", fileName);
|
||||
#endif
|
||||
|
||||
var simpleFilename = Path.GetFileNameWithoutExtension(fileName);
|
||||
var languageMatch = SubtitleLanguageRegex.Match(simpleFilename);
|
||||
|
||||
if (languageMatch.Success)
|
||||
{
|
||||
var isoCode = languageMatch.Groups["iso_code"].Value;
|
||||
var isoLanguage = IsoLanguages.Find(isoCode);
|
||||
|
||||
return isoLanguage?.Language ?? Language.Unknown;
|
||||
}
|
||||
#if !LIBRARY
|
||||
Logger.Debug("Unable to parse langauge from subtitle file: {0}", fileName);
|
||||
#endif
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
#if !LIBRARY
|
||||
Logger.Debug("Failed parsing langauge from subtitle file: {0}", fileName);
|
||||
#endif
|
||||
}
|
||||
|
||||
return Language.Unknown;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.Languages;
|
||||
using Prowlarr.Http;
|
||||
using Prowlarr.Http.REST;
|
||||
|
||||
namespace Prowlarr.Api.V1.Languages
|
||||
{
|
||||
[V1ApiController()]
|
||||
public class LanguageController : RestController<LanguageResource>
|
||||
{
|
||||
public override LanguageResource GetResourceById(int id)
|
||||
{
|
||||
var language = (Language)id;
|
||||
|
||||
return new LanguageResource
|
||||
{
|
||||
Id = (int)language,
|
||||
Name = language.ToString()
|
||||
};
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Produces("application/json")]
|
||||
public List<LanguageResource> GetAll()
|
||||
{
|
||||
return Language.All.Select(l => new LanguageResource
|
||||
{
|
||||
Id = (int)l,
|
||||
Name = l.ToString()
|
||||
})
|
||||
.OrderBy(l => l.Name)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
using Prowlarr.Http.REST;
|
||||
|
||||
namespace Prowlarr.Api.V1.Languages
|
||||
{
|
||||
public class LanguageResource : RestResource
|
||||
{
|
||||
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Include)]
|
||||
public new int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string NameLower => Name.ToLowerInvariant();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue