Skip to content

Commit

Permalink
Use m translations instead of localItems
Browse files Browse the repository at this point in the history
  • Loading branch information
nas-tabchiche committed Jun 12, 2024
1 parent 8b91f9d commit 89399d0
Show file tree
Hide file tree
Showing 22 changed files with 67 additions and 70 deletions.
12 changes: 6 additions & 6 deletions frontend/src/lib/components/Breadcrumbs/Breadcrumbs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
{#if c.icon}
<i class={c.icon} />
{/if}
{#if localItems()[c.label]}
{localItems()[c.label]}
{#if m[c.label]}
{m[c.label]()}
{:else}
{c.label}
{/if}
Expand All @@ -82,8 +82,8 @@
{#if c.icon}
<i class={c.icon} />
{/if}
{#if localItems()[c.label]}
{localItems()[c.label]}
{#if m[c.label]}
{m[c.label]()}
{:else}
{c.label}
{/if}
Expand All @@ -93,8 +93,8 @@
{#if c.icon}
<i class={c.icon} />
{/if}
{#if localItems()[c.label]}
{localItems()[c.label]}
{#if m[c.label]()}
{m[c.label]()}
{:else}
{c.label}
{/if}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/lib/components/Forms/AutocompleteSelect.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { formFieldProxy } from 'sveltekit-superforms';
import { localItems, toCamelCase } from '$lib/utils/locales';
import { languageTag } from '$paraglide/runtime';
import * as m from '$paraglide/messages.js';
export let label: string | undefined = undefined;
export let field: string;
Expand Down Expand Up @@ -89,8 +89,8 @@
{#if option.suggested}
<span class="text-indigo-600">{option.label}</span>
<span class="text-sm text-gray-500"> (suggested)</span>
{:else if translateOptions && localItems()[toCamelCase(option.label)]}
{localItems()[toCamelCase(option.label)]}
{:else if translateOptions && m[toCamelCase(option.label)]()}ption.label)]}
{m[toCamelCase(option.label)]()}
{:else}
{option.label}
{/if}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/lib/components/Forms/Select.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { formFieldProxy, type SuperForm } from 'sveltekit-superforms';
import { localItems, toCamelCase } from '$lib/utils/locales';
import { languageTag } from '$paraglide/runtime';
import * as m from '$paraglide/messages.js';
import type { AnyZodObject } from 'zod';
let _class = '';
Expand Down Expand Up @@ -62,8 +62,8 @@
{/if}
{#each options as option}
<option value={option.value} style="background-color: {color_map[option.value]}">
{#if localItems()[toCamelCase(option.label)]}
{localItems()[toCamelCase(option.label)]}
{#if m[toCamelCase(option.label)]()}
{m[toCamelCase(option.label)]()}
{:else}
{option.label}
{/if}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
{#if value}
{m.missingMandatoyObjects1({ model: $modalStore[0].body })}:
{#each value as key}
<li class="font-bold">{localItems()[toCamelCase(key)]}</li>
<li class="font-bold">{m[toCamelCase(key)]() ?? key}</li>
{/each}
{m.missingMandatoyObjects2()}.
{/if}
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/lib/components/ModelTable/ModelTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
<thead class="table-head {regionHead}">
<tr>
{#each Object.entries(source.head) as [key, heading]}
<Th {handler} orderBy={key} class="{regionHeadCell}">{localItems()[heading]}</Th>
<Th {handler} orderBy={key} class="{regionHeadCell}">{m[heading]()}</Th>
{/each}
{#if displayActions}
<th class="{regionHeadCell} select-none text-end"></th>
Expand Down Expand Up @@ -210,7 +210,7 @@
{#if tagData && tags}
{@const {text, cssClasses} = tagData}
<span class={cssClasses}>
{localItems()[text]}
{m[text]()}
</span>
{/if}
{/each}
Expand Down Expand Up @@ -247,17 +247,17 @@
{/if}
{:else if value && value.hexcolor}
<p class="flex w-fit min-w-24 justify-center px-2 py-1 rounded-md ml-2 whitespace-nowrap" style="background-color: {value.hexcolor}">
{#if localItems()[toCamelCase(value.name ?? value.str ?? '-')]}
{localItems()[toCamelCase(value.name ?? value.str ?? '-')]}
{#if m[toCamelCase(value.name ?? value.str ?? '-')]()}
{m[toCamelCase(value.name ?? value.str ?? '-')]() ?? value.name ?? value.str ?? '-'}
{:else}
{value.name ?? value.str ?? '-'}
{/if}
</p>
{:else if ISO_8601_REGEX.test(value)}
{formatDateOrDateTime(value, languageTag())}
{:else}
{#if localItems()[toCamelCase(value)]}
{localItems()[toCamelCase(value)]}
{#if m[toCamelCase(value)]()}
{m[toCamelCase(value)]() ?? value}
{:else}
{value ?? '-'}
{/if}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
export const meta: any = undefined;
</script>

<span>{cell.folder} - {localItems()[toCamelCase(cell.role)]}</span>
<span>{cell.folder} - {m[toCamelCase(cell.role)]() ?? cell.role}</span>
5 changes: 2 additions & 3 deletions frontend/src/lib/components/SideBar/SideBarCategory.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<script lang="ts">
export let item: any; // Specify the type of 'item' as a key of 'Sidebar'
import { localItems } from '$lib/utils/locales';
import { languageTag } from '$paraglide/runtime';
import * as m from '$paraglide/messages.js';
</script>

<span class="whitespace-nowrap text-primary-800 font-semibold uppercase tracking-tighter text-xs">
{localItems()[item.name]}
{m[item.name]()}
</span>
2 changes: 1 addition & 1 deletion frontend/src/lib/components/SideBar/SideBarItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
>
<span class="px-4 flex items-center w-full space-x-2 text-xs">
<i class="{item.fa_icon} w-1/12" />
<span class="text-sm tracking-wide truncate">{localItems()[item.name]}</span>
<span class="text-sm tracking-wide truncate">{m[item.name]()}</span>
</span></a
>
{/each}
6 changes: 3 additions & 3 deletions frontend/src/routes/(app)/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { pageTitle } from '$lib/utils/stores';
import { localItems } from '$lib/utils/locales';
import { languageTag } from '$paraglide/runtime';
import * as m from '$paraglide/messages.js';
let sidebarOpen = true;
Expand All @@ -26,8 +26,8 @@
<svelte:fragment slot="pageHeader">
<AppBar background="bg-white" padding="py-2 px-4">
<span class="text-2xl font-bold pb-1" id="page-title">
{#if localItems()[$pageTitle]}
{localItems()[$pageTitle]}
{#if $pageTitle && m[$pageTitle]}
{m[$pageTitle]() ?? $pageTitle}
{:else}
{$pageTitle}
{/if}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routes/(app)/[model=urlmodel]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export const actions: Actions = {
const response = await res.json();
console.log(response);
if (response.error) {
setFlash({ type: 'error', message: localItems()[response.error] }, event);
setFlash({ type: 'error', message: m[response.error]() }, event);
return fail(403, { form: deleteForm });
}
if (response.non_field_errors) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routes/(app)/[model=urlmodel]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
data-testid="add-button"
on:click={modalCreateForm}
><i class="fa-solid fa-plus mr-2" />
{localItems()['add' + capitalizeFirstLetter(data.model.localName)]}
{m['add' + capitalizeFirstLetter(data.model.localName)]()}
</button>
{:else if data.URLModel === 'risk-matrices'}
<a href="/libraries" class="btn variant-filled-primary" data-testid="add-button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
class="text-sm font-medium text-gray-800"
data-testid="{key.replace('_', '-')}-field-title"
>
{localItems()[toCamelCase(key)]}
{m[toCamelCase(key)]() ?? key}
</div>
<ul class="text-sm">
<li
Expand Down Expand Up @@ -233,8 +233,8 @@
<a href={value} target="_blank" class="anchor">{value}</a>
{:else if ISO_8601_REGEX.test(value)}
{formatDateOrDateTime(value, languageTag())}
{:else if localItems()[toCamelCase((value.str || value.name) ?? value)]}
{localItems()[toCamelCase((value.str || value.name) ?? value)]}
{:else if m[toCamelCase((value.str || value.name) ?? value)]}
{m[toCamelCase((value.str || value.name) ?? value)]()}
{:else}
{(value.str || value.name) ?? value}
{/if}
Expand All @@ -261,7 +261,7 @@
<TabGroup justify="justify-center">
{#each Object.entries(data.relatedModels) as [urlmodel, model], index}
<Tab bind:group={tabSet} value={index} name={`${urlmodel}_tab`}>
{localItems()[model.info.localNamePlural]}
{m[model.info.localNamePlural]()}
{#if model.table.body.length > 0}
<span class="badge variant-soft-secondary">{model.table.body.length}</span>
{/if}
Expand All @@ -272,7 +272,7 @@
{#if tabSet === index}
<div class="flex flex-row justify-between px-4 py-2">
<h4 class="font-semibold lowercase capitalize-first my-auto">
{localItems()['associated' + capitalizeFirstLetter(model.info.localNamePlural)]}
{m['associated' + capitalizeFirstLetter(model.info.localNamePlural)]()}
</h4>
</div>
{#if model.table}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
{#if key === 'urn'}
{m.urn()}
{:else}
{localItems()[toCamelCase(key)]}
{m[toCamelCase(key)]() ?? key}
{/if}
</div>
<ul class="text-sm">
Expand Down Expand Up @@ -157,8 +157,8 @@
)?.urlModel
}/${value.id}`}
<a href={itemHref} class="anchor">{value.str}</a>
{:else if localItems()[toCamelCase(value.str ?? value)]}
{localItems()[toCamelCase(value.str ?? value)]}
{:else if m[toCamelCase(value.str ?? value)]()}
{m[toCamelCase(value.str ?? value)]() ?? value.str ?? value}
{:else}
{value.str ?? value}
{/if}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routes/(app)/evidences/[id=uuid]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
class="text-sm font-medium text-gray-800 capitalize-first"
data-testid={key.replace('_', '-') + '-field-title'}
>
{localItems()[toCamelCase(key)]}
{m[toCamelCase(key)]() ?? key}
</div>
<ul class="text-sm">
<li
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
{#if key === 'urn'}
{m.urn()}
{:else}
{localItems()[toCamelCase(key)]}
{m[toCamelCase(key)]() ?? key}
{/if}
</div>
<ul class="text-sm">
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routes/(app)/my-profile/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<div class="flex flex-col w-1/2 border p-2 rounded-lg shadow-lg space-y-4">
{#each Object.entries(filterUserData()) as [label, value]}
<div class="flex flex-col">
<p class="font-semibold text-sm">{localItems()[label]}</p>
<p class="font-semibold text-sm">{m[label]()}</p>
<p class="text-sm">{value}</p>
</div>
{/each}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,7 @@
<ul>
<li class="pb-1">
<span class="font-semibold">{m.status()}:</span>
{risk_assessment.status === null
? '--'
: localItems()[toCamelCase(risk_assessment.status)]}
{risk_assessment.status === null ? '--' : m[toCamelCase(risk_assessment.status)]()}
</li>
<li class="pb-1">
<span class="font-semibold">{m.authors()}:</span>
Expand Down
32 changes: 16 additions & 16 deletions frontend/src/routes/(app)/risk-scenarios/[id=uuid]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<span>
<p class="text-sm font-semibold text-gray-400">{m.treatmentStatus()}</p>
<p class="text-sm font-semibold">
{localItems()[toCamelCase(data.scenario.treatment)]}
{m[toCamelCase(data.scenario.treatment)]() ?? data.scenario.treatment}
</p>
</span>
</div>
Expand Down Expand Up @@ -120,8 +120,8 @@
class="text-sm text-center font-semibold p-2 rounded-md w-20"
style="background-color: {color_map[data.scenario.current_proba]}"
>
{#if localItems()[toCamelCase(data.scenario.current_proba)]}
{localItems()[toCamelCase(data.scenario.current_proba)]}
{#if m[toCamelCase(data.scenario.current_proba)]()}
{m[toCamelCase(data.scenario.current_proba)]() ?? data.scenario.current_proba}
{:else}
{data.scenario.current_proba}
{/if}
Expand All @@ -134,8 +134,8 @@
class="text-sm text-center font-semibold p-2 rounded-md w-20"
style="background-color: {color_map[data.scenario.current_impact]}"
>
{#if localItems()[toCamelCase(data.scenario.current_impact)]}
{localItems()[toCamelCase(data.scenario.current_impact)]}
{#if m[toCamelCase(data.scenario.current_impact)]()}
{m[toCamelCase(data.scenario.current_impact)]() ?? data.scenario.current_impact}
{:else}
{data.scenario.current_impact}
{/if}
Expand All @@ -148,8 +148,8 @@
class="text-sm text-center font-semibold p-2 rounded-md w-20"
style="background-color: {data.scenario.current_level.hexcolor}"
>
{#if localItems()[toCamelCase(data.scenario.current_level.name)]}
{localItems()[toCamelCase(data.scenario.current_level.name)]}
{#if m[toCamelCase(data.scenario.current_level.name)]()}
{m[toCamelCase(data.scenario.current_level.name)]() ?? data.scenario.current_level.name}
{:else}
{data.scenario.current_level.name}
{/if}
Expand All @@ -170,8 +170,8 @@
class="text-sm text-center font-semibold p-2 rounded-md w-20"
style="background-color: {color_map[data.scenario.residual_proba]}"
>
{#if localItems()[toCamelCase(data.scenario.residual_proba)]}
{localItems()[toCamelCase(data.scenario.residual_proba)]}
{#if m[toCamelCase(data.scenario.residual_proba)]()}
{m[toCamelCase(data.scenario.residual_proba)]() ?? data.scenario.residual_proba}
{:else}
{data.scenario.residual_proba}
{/if}
Expand All @@ -184,8 +184,8 @@
class="text-sm text-center font-semibold p-2 rounded-md w-20"
style="background-color: {color_map[data.scenario.residual_impact]}"
>
{#if localItems()[toCamelCase(data.scenario.residual_impact)]}
{localItems()[toCamelCase(data.scenario.residual_impact)]}
{#if m[toCamelCase(data.scenario.residual_impact)]()}
{m[toCamelCase(data.scenario.residual_impact)]() ?? data.scenario.residual_impact}
{:else}
{data.scenario.residual_impact}
{/if}
Expand All @@ -198,8 +198,8 @@
class="text-sm text-center font-semibold p-2 rounded-md w-20"
style="background-color: {data.scenario.residual_level.hexcolor}"
>
{#if localItems()[toCamelCase(data.scenario.residual_level.name)]}
{localItems()[toCamelCase(data.scenario.residual_level.name)]}
{#if m[toCamelCase(data.scenario.residual_level.name)]()}
{m[toCamelCase(data.scenario.residual_level.name)]() ?? data.scenario.residual_level.name}
{:else}
{data.scenario.residual_level.name}
{/if}
Expand All @@ -215,10 +215,10 @@
{data.scenario.strength_of_knowledge.symbol}
{/if}
<span class="font-semibold">
{#if localItems()[toCamelCase(data.scenario.strength_of_knowledge.name)]}
{localItems()[toCamelCase(data.scenario.strength_of_knowledge.name)]}
{#if m[toCamelCase(data.scenario.strength_of_knowledge.name)]()}
{m[toCamelCase(data.scenario.strength_of_knowledge.name)]() ?? data.scenario.strength_of_knowledge.name}
{:else}
{localItems()['undefined']}
{m['undefined']()}
{/if}
</span>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
class="flex font-medium w-32 justify-center p-2 rounded-token"
style="background-color: {riskLevel.hexcolor}"
>
{#if localItems()[toCamelCase(riskLevel.name)]}
{localItems()[toCamelCase(riskLevel.name)]}
{#if m[toCamelCase(riskLevel.name)]()}
{m[toCamelCase(riskLevel.name)]() ?? riskLevel.name}
{:else}
{riskLevel.name}
{/if}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/routes/(app)/scoring-assistant/selector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
$: dispatch('change', value);
</script>

<div>{localItems()[text]}</div>
<div>{m[text]()}</div>
<select class="select w-full" {id} bind:value {disabled}>
{#each choices as text, i}
<option class="text-{i}" value={i}
>{i}{#if text} - {localItems()[text]}{/if}</option
>{i}{#if text} - {m[text]()}{/if}</option
>
{/each}
</select>
Loading

0 comments on commit 89399d0

Please sign in to comment.