mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
chore(web): translate alt text (#10922)
* chore(web): translate image alt text * fix: capitalize translations, improve unit test * fix: unit testing against the actual en.json file * fix: use derived store to generate alt text
This commit is contained in:
parent
a5467d60ea
commit
39221c8d1f
7 changed files with 113 additions and 29 deletions
68
web/src/lib/utils/thumbnail-util.spec.ts
Normal file
68
web/src/lib/utils/thumbnail-util.spec.ts
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
import { getAltText } from '$lib/utils/thumbnail-util';
|
||||
import { AssetTypeEnum, type AssetResponseDto } from '@immich/sdk';
|
||||
import { init, register, waitLocale } from 'svelte-i18n';
|
||||
|
||||
describe('getAltText', () => {
|
||||
beforeAll(async () => {
|
||||
await init({ fallbackLocale: 'en-US' });
|
||||
register('en-US', () => import('$lib/i18n/en.json'));
|
||||
await waitLocale('en-US');
|
||||
});
|
||||
|
||||
it('defaults to the description, if available', () => {
|
||||
const asset = {
|
||||
exifInfo: { description: 'description' },
|
||||
} as AssetResponseDto;
|
||||
|
||||
getAltText.subscribe((fn) => {
|
||||
expect(fn(asset)).toEqual('description');
|
||||
});
|
||||
});
|
||||
|
||||
it('includes the city and country', () => {
|
||||
const asset = {
|
||||
exifInfo: { city: 'city', country: 'country' },
|
||||
localDateTime: '2024-01-01T12:00:00.000Z',
|
||||
} as AssetResponseDto;
|
||||
|
||||
getAltText.subscribe((fn) => {
|
||||
expect(fn(asset)).toEqual('Image taken in city, country on January 1, 2024');
|
||||
});
|
||||
});
|
||||
|
||||
// convert the people tests into an it.each
|
||||
it.each([
|
||||
[[{ name: 'person' }], 'Image taken with person on January 1, 2024'],
|
||||
[[{ name: 'person1' }, { name: 'person2' }], 'Image taken with person1 and person2 on January 1, 2024'],
|
||||
[
|
||||
[{ name: 'person1' }, { name: 'person2' }, { name: 'person3' }],
|
||||
'Image taken with person1, person2, and person3 on January 1, 2024',
|
||||
],
|
||||
[
|
||||
[{ name: 'person1' }, { name: 'person2' }, { name: 'person3' }, { name: 'person4' }],
|
||||
'Image taken with person1, person2, and 2 others on January 1, 2024',
|
||||
],
|
||||
])('includes people, correctly formatted', (people, expected) => {
|
||||
const asset = {
|
||||
localDateTime: '2024-01-01T12:00:00.000Z',
|
||||
people,
|
||||
} as AssetResponseDto;
|
||||
|
||||
getAltText.subscribe((fn) => {
|
||||
expect(fn(asset)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
it('handles videos, location, people, and date', () => {
|
||||
const asset = {
|
||||
exifInfo: { city: 'city', country: 'country' },
|
||||
localDateTime: '2024-01-01T12:00:00.000Z',
|
||||
people: [{ name: 'person1' }, { name: 'person2' }, { name: 'person3' }, { name: 'person4' }, { name: 'person5' }],
|
||||
type: AssetTypeEnum.Video,
|
||||
} as AssetResponseDto;
|
||||
|
||||
getAltText.subscribe((fn) => {
|
||||
expect(fn(asset)).toEqual('Video taken in city, country with person1, person2, and 3 others on January 1, 2024');
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue