Fixed: Displaying audio and subtitle languages in UI

This commit is contained in:
Mark McDowall 2023-01-04 21:23:57 -08:00
parent 84e6649724
commit 1394122842
7 changed files with 65 additions and 14 deletions

View File

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

View File

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

View File

@ -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;
}

View File

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

View File

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

View File

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

View File

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