Skip to content

Commit

Permalink
fix: try languages in correct order
Browse files Browse the repository at this point in the history
  • Loading branch information
mtdvlpr committed Dec 6, 2024
1 parent e4d75f8 commit fed424f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
10 changes: 7 additions & 3 deletions src/components/dialog/DialogStudyBible.vue
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,13 @@ const addStudyBibleMedia = async (mediaItem: MultimediaItem) => {
};
const langsToTry = [
currentSettings.value?.lang,
currentSettings.value?.langFallback,
'E',
...new Set([
/* eslint-disable perfectionist/sort-sets */
currentSettings.value?.lang,
currentSettings.value?.langFallback,
'E',
/* eslint-enable perfectionist/sort-sets */
]),
].filter((l) => l !== undefined && l !== null);
let mediaInfo, mediaItemFiles;
for (const lang of langsToTry) {
Expand Down
34 changes: 23 additions & 11 deletions src/helpers/jw-media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,10 @@ const getStudyBible = async () => {
const currentStateStore = useCurrentStateStore();
const languages = [
...new Set([
/* eslint-disable perfectionist/sort-sets */
currentStateStore.currentSettings?.lang,
currentStateStore.currentSettings?.langFallback,
/* eslint-enable perfectionist/sort-sets */
]),
].filter((l): l is JwLangCode => !!l);
let nwtStyDb: null | string = null;
Expand Down Expand Up @@ -1003,9 +1005,13 @@ export const getAudioBibleMedia = async (force = false) => {
pub: 'nwt',
};
const languages = [
currentStateStore.currentSettings.lang,
currentStateStore.currentSettings?.langFallback,
].filter(Boolean) as JwLangCode[];
...new Set([
/* eslint-disable perfectionist/sort-sets */
currentStateStore.currentSettings.lang,
currentStateStore.currentSettings?.langFallback,
/* eslint-enable perfectionist/sort-sets */
]),
].filter((l): l is JwLangCode => !!l);

const backupNameNeeded: number[] = [];

Expand Down Expand Up @@ -1513,7 +1519,7 @@ export const getWeMedia = async (lookupDate: Date) => {
} else {
songs = videosNotInParagraphs.slice(0, 2); // after FEB_2023, the first two videos from DocumentMultimedia are the songs
}
let songLangs: string[] = [];
let songLangs: ('' | JwLangCode)[] = [];
try {
songLangs = executeQuery<MultimediaExtractItem>(
db,
Expand All @@ -1528,7 +1534,9 @@ export const getWeMedia = async (lookupDate: Date) => {
.sort((a, b) => a.BeginParagraphOrdinal - b.BeginParagraphOrdinal)
.map((item) => {
const match = item.Link.match(/\/(.*)\//);
const langOverride = match ? match[1].split(':')[0] : '';
const langOverride = match
? (match[1].split(':')[0] as JwLangCode)
: '';
return langOverride === currentStateStore.currentSettings?.lang
? ''
: langOverride;
Expand All @@ -1539,10 +1547,10 @@ export const getWeMedia = async (lookupDate: Date) => {
() => currentStateStore.currentSettings?.lang || 'E',
);
}
const mergedSongs = songs
const mergedSongs: MultimediaItem[] = songs
.map((song, index) => ({
...song,
...(songLangs[index] ? { LangOverride: songLangs[index] } : {}),
...(songLangs[index] ? { AlternativeLanguage: songLangs[index] } : {}),
}))
.sort(
(a, b) =>
Expand All @@ -1568,7 +1576,9 @@ export const getWeMedia = async (lookupDate: Date) => {
);
if (multimediaMepsLangItem?.MepsLanguageIndex !== undefined) {
const mepsLang = mepslangs[multimediaMepsLangItem.MepsLanguageIndex];
if (mepsLang) media.AlternativeLanguage = mepsLang;
if (mepsLang) {
media.AlternativeLanguage = mepsLang;
}
}
const videoMarkers = getMediaVideoMarkers(
{ db, docId },
Expand Down Expand Up @@ -1723,11 +1733,13 @@ export async function processMissingMediaInfo(allMedia: MultimediaItem[]) {
for (const { media } of mediaToProcess) {
const langsWritten = [
...new Set([
currentStateStore.currentSettings?.lang,
currentStateStore.currentSettings?.langFallback,
media.AlternativeLanguage,
/* eslint-disable perfectionist/sort-sets */
media.MepsLanguageIndex !== undefined &&
mepslangs[media.MepsLanguageIndex],
media.AlternativeLanguage,
currentStateStore.currentSettings?.lang,
currentStateStore.currentSettings?.langFallback,
/* eslint-disable perfectionist/sort-sets */
]),
];
for (const langwritten of langsWritten) {
Expand Down

0 comments on commit fed424f

Please sign in to comment.