Fixed: Displaying audio and subtitle languages in UI

pull/5349/head
Mark McDowall 1 year ago
parent 84e6649724
commit 1394122842

@ -1,6 +1,7 @@
import _ from 'lodash'; import _ from 'lodash';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import React from 'react'; import React from 'react';
import getLanguageName from 'Utilities/String/getLanguageName';
import * as mediaInfoTypes from './mediaInfoTypes'; import * as mediaInfoTypes from './mediaInfoTypes';
function formatLanguages(languages) { function formatLanguages(languages) {
@ -8,7 +9,7 @@ function formatLanguages(languages) {
return null; return null;
} }
const splitLanguages = _.uniq(languages.split(' / ')); const splitLanguages = _.uniq(languages.split('/')).map((l) => getLanguageName(l));
if (splitLanguages.length > 3) { if (splitLanguages.length > 3) {
return ( return (
@ -40,18 +41,15 @@ function MediaInfo(props) {
return ( return (
<span> <span>
{ {
!!audioCodec && audioCodec ? audioCodec : ''
audioCodec
} }
{ {
!!audioCodec && !!audioChannels && audioCodec && audioChannels ? ' - ' : ''
' - '
} }
{ {
!!audioChannels && audioChannels ? audioChannels.toFixed(1) : ''
audioChannels.toFixed(1)
} }
</span> </span>
); );

@ -9,7 +9,7 @@ import createSettingsSectionSelector from 'Store/Selectors/createSettingsSection
import UISettings from './UISettings'; import UISettings from './UISettings';
const SECTION = 'ui'; const SECTION = 'ui';
const FILTER_LANGUAGES = ['Any', 'Unknown']; const FILTER_LANGUAGES = ['Any', 'Unknown', 'Original'];
function createFilteredLanguagesSelector() { function createFilteredLanguagesSelector() {
return createSelector( return createSelector(

@ -0,0 +1,27 @@
import createAjaxRequest from 'Utilities/createAjaxRequest';
function getTranslations() {
return createAjaxRequest({
global: false,
dataType: 'json',
url: '/localization/language'
}).request;
}
let languageNames = new Intl.DisplayNames(['en'], { type: 'language' });
getTranslations().then((data) => {
const names = new Intl.DisplayNames([data.identifier], { type: 'language' });
if (names) {
languageNames = names;
}
});
export default function getLanguageName(code) {
if (!languageNames) {
return code;
}
return languageNames.of(code) ?? code;
}

@ -20,6 +20,7 @@ namespace NzbDrone.Core.Localization
Dictionary<string, string> GetLocalizationDictionary(); Dictionary<string, string> GetLocalizationDictionary();
string GetLocalizedString(string phrase); string GetLocalizedString(string phrase);
string GetLocalizedString(string phrase, string language); string GetLocalizedString(string phrase, string language);
string GetLanguageIdentifier();
} }
public class LocalizationService : ILocalizationService, IHandleAsync<ConfigSavedEvent> public class LocalizationService : ILocalizationService, IHandleAsync<ConfigSavedEvent>
@ -45,14 +46,14 @@ namespace NzbDrone.Core.Localization
public Dictionary<string, string> GetLocalizationDictionary() public Dictionary<string, string> GetLocalizationDictionary()
{ {
var language = GetSetLanguageFileName(); var language = GetLanguageFileName();
return GetLocalizationDictionary(language); return GetLocalizationDictionary(language);
} }
public string GetLocalizedString(string phrase) public string GetLocalizedString(string phrase)
{ {
var language = GetSetLanguageFileName(); var language = GetLanguageFileName();
return GetLocalizedString(phrase, language); return GetLocalizedString(phrase, language);
} }
@ -66,7 +67,7 @@ namespace NzbDrone.Core.Localization
if (language.IsNullOrWhiteSpace()) if (language.IsNullOrWhiteSpace())
{ {
language = GetSetLanguageFileName(); language = GetLanguageFileName();
} }
if (language == null) if (language == null)
@ -84,19 +85,24 @@ namespace NzbDrone.Core.Localization
return phrase; return phrase;
} }
private string GetSetLanguageFileName() public string GetLanguageIdentifier()
{ {
var isoLanguage = IsoLanguages.Get((Language)_configService.UILanguage); var isoLanguage = IsoLanguages.Get((Language)_configService.UILanguage);
var language = isoLanguage.TwoLetterCode; var language = isoLanguage.TwoLetterCode;
if (isoLanguage.CountryCode.IsNotNullOrWhiteSpace()) if (isoLanguage.CountryCode.IsNotNullOrWhiteSpace())
{ {
language = string.Format("{0}_{1}", language, isoLanguage.CountryCode); language = $"{language}-{isoLanguage.CountryCode.ToUpperInvariant()}";
} }
return language; return language;
} }
private string GetLanguageFileName()
{
return GetLanguageIdentifier().Replace("-", "_").ToLowerInvariant();
}
private Dictionary<string, string> GetLocalizationDictionary(string language) private Dictionary<string, string> GetLocalizationDictionary(string language)
{ {
if (string.IsNullOrEmpty(language)) if (string.IsNullOrEmpty(language))

@ -1,4 +1,4 @@
using NzbDrone.Core.Languages; using NzbDrone.Core.Languages;
namespace NzbDrone.Core.Parser namespace NzbDrone.Core.Parser
{ {
@ -8,6 +8,7 @@ namespace NzbDrone.Core.Parser
public string ThreeLetterCode { get; set; } public string ThreeLetterCode { get; set; }
public string CountryCode { get; set; } public string CountryCode { get; set; }
public Language Language { get; set; } public Language Language { get; set; }
public string CountyCodeLower => CountryCode?.ToLower();
public IsoLanguage(string twoLetterCode, string countryCode, string threeLetterCode, Language language) public IsoLanguage(string twoLetterCode, string countryCode, string threeLetterCode, Language language)
{ {

@ -0,0 +1,7 @@
namespace Sonarr.Api.V3.Localization
{
public class LanguageResource
{
public string Identifier { get; set; }
}
}

@ -26,5 +26,17 @@ namespace Sonarr.Api.V3.Localization
{ {
return _localizationService.GetLocalizationDictionary().ToResource(); return _localizationService.GetLocalizationDictionary().ToResource();
} }
[HttpGet("language")]
[Produces("application/json")]
public LanguageResource GetLanguage()
{
var identifier = _localizationService.GetLanguageIdentifier();
return new LanguageResource
{
Identifier = identifier
};
}
} }
} }

Loading…
Cancel
Save