feat: add French localization support for character attributes and improve character display logic
All checks were successful
Build Docker Image / build (push) Successful in 1m18s
All checks were successful
Build Docker Image / build (push) Successful in 1m18s
- Added optional French names, affiliations, origins, and epithets to character records. - Updated character import logic to handle new French fields. - Enhanced character search and display components to show French names and epithets based on selected language. - Modified database schema to include French fields for characters. - Improved error handling in daily character setup to check for existing characters. - Refactored components to utilize helper functions for displaying names and attributes based on language.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { formatBounty } from '$lib';
|
||||
import { resolve } from '$app/paths';
|
||||
import type { CharacterWithRelations } from '$lib/server/daily-character';
|
||||
import { t } from '$lib/i18n';
|
||||
import { language, t } from '$lib/i18n';
|
||||
|
||||
export let selectedCharacters: CharacterWithRelations[];
|
||||
export let dailyCharacter: CharacterWithRelations;
|
||||
@@ -62,6 +63,52 @@
|
||||
const dailyPrimary = firstAffiliation(dailyAffiliations);
|
||||
return characterPrimary === dailyPrimary;
|
||||
}
|
||||
|
||||
$: isFrench = $language === 'fr';
|
||||
|
||||
function getDisplayName(character: CharacterWithRelations): string {
|
||||
if (isFrench && typeof character.frName === 'string' && character.frName.length > 0) {
|
||||
return character.frName;
|
||||
}
|
||||
|
||||
return character.name;
|
||||
}
|
||||
|
||||
function getWikiUrl(character: CharacterWithRelations): string {
|
||||
if (isFrench && typeof character.frUrl === 'string' && character.frUrl.length > 0) {
|
||||
return character.frUrl;
|
||||
}
|
||||
|
||||
return character.url || '';
|
||||
}
|
||||
|
||||
function getWikiBaseUrl(): string {
|
||||
return isFrench ? 'https://onepiece.fandom.com/fr/wiki/' : 'https://onepiece.fandom.com/wiki/';
|
||||
}
|
||||
|
||||
function getDisplayOrigin(character: CharacterWithRelations): string | null {
|
||||
if (isFrench && typeof character.frOrigin === 'string' && character.frOrigin.length > 0) {
|
||||
return character.frOrigin;
|
||||
}
|
||||
|
||||
return character.origin;
|
||||
}
|
||||
|
||||
function hasMatchingOrigin(characterEntry: CharacterWithRelations, dailyEntry: CharacterWithRelations): boolean {
|
||||
return getDisplayOrigin(characterEntry) === getDisplayOrigin(dailyEntry);
|
||||
}
|
||||
|
||||
function getDisplayArcName(character: CharacterWithRelations): string | null {
|
||||
if (isFrench && typeof character.frArcName === 'string' && character.frArcName.length > 0) {
|
||||
return character.frArcName;
|
||||
}
|
||||
|
||||
return character.arcName;
|
||||
}
|
||||
|
||||
function hasMatchingArc(characterEntry: CharacterWithRelations, dailyEntry: CharacterWithRelations): boolean {
|
||||
return getDisplayArcName(characterEntry) === getDisplayArcName(dailyEntry);
|
||||
}
|
||||
</script>
|
||||
|
||||
<section
|
||||
@@ -197,14 +244,14 @@
|
||||
>
|
||||
{#if character.pictureUrl}
|
||||
<a
|
||||
href={'https://onepiece.fandom.com/fr/wiki/' + character.url}
|
||||
href={getWikiBaseUrl() + getWikiUrl(character)}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="block h-full w-full"
|
||||
>
|
||||
<img
|
||||
src={character.pictureUrl}
|
||||
alt={character.name}
|
||||
alt={getDisplayName(character)}
|
||||
class="h-full w-full cursor-pointer object-cover transition-opacity hover:opacity-80"
|
||||
/>
|
||||
</a>
|
||||
@@ -214,7 +261,7 @@
|
||||
>
|
||||
<span
|
||||
class="line-clamp-3 text-center text-xs font-semibold sm:text-sm md:text-xl"
|
||||
>{character.name}</span
|
||||
>{getDisplayName(character)}</span
|
||||
>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -407,13 +454,12 @@
|
||||
<!-- Origine -->
|
||||
{#if columnVisibility.origin !== false}
|
||||
<div
|
||||
class="h-16 w-16 shrink-0 rounded-lg border border-white/10 sm:h-20 sm:w-20 md:h-24 md:w-24 {character.origin ===
|
||||
dailyCharacter.origin
|
||||
class="h-16 w-16 shrink-0 rounded-lg border border-white/10 sm:h-20 sm:w-20 md:h-24 md:w-24 {hasMatchingOrigin(character, dailyCharacter)
|
||||
? 'bg-emerald-600/90'
|
||||
: 'bg-red-900/60'} flex items-center justify-center p-1 sm:p-2"
|
||||
>
|
||||
<p class="text-center text-[10px] font-bold text-white sm:text-xs md:text-sm">
|
||||
{character.origin || $t.game.components.guessHistory.unknown}
|
||||
{getDisplayOrigin(character) || $t.game.components.guessHistory.unknown}
|
||||
</p>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -421,12 +467,11 @@
|
||||
<!-- Arc -->
|
||||
{#if columnVisibility.arc !== false}
|
||||
<div
|
||||
class="h-16 w-16 shrink-0 rounded-lg border border-white/10 sm:h-20 sm:w-20 md:h-24 md:w-24 {character.arcName ===
|
||||
dailyCharacter.arcName
|
||||
class="h-16 w-16 shrink-0 rounded-lg border border-white/10 sm:h-20 sm:w-20 md:h-24 md:w-24 {hasMatchingArc(character, dailyCharacter)
|
||||
? 'bg-emerald-600/90'
|
||||
: 'bg-red-900/60'} relative flex items-center justify-center overflow-hidden p-1 sm:p-2"
|
||||
>
|
||||
{#if character.arcName !== dailyCharacter.arcName && character.firstAppearance && dailyCharacter.firstAppearance && character.firstAppearance !== dailyCharacter.firstAppearance}
|
||||
{#if !hasMatchingArc(character, dailyCharacter) && character.firstAppearance && dailyCharacter.firstAppearance && character.firstAppearance !== dailyCharacter.firstAppearance}
|
||||
<div
|
||||
class="pointer-events-none absolute h-full w-full opacity-30"
|
||||
style="
|
||||
@@ -440,7 +485,7 @@
|
||||
<p
|
||||
class="relative z-10 text-center text-[10px] font-bold text-white sm:text-xs md:text-sm"
|
||||
>
|
||||
{character.arcName || $t.game.components.guessHistory.unknown}
|
||||
{getDisplayArcName(character) || $t.game.components.guessHistory.unknown}
|
||||
</p>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user