Add translations to card component

This commit is contained in:
Corinne Durrmeyer 2024-10-23 11:11:37 +02:00
parent 0b5803dae6
commit 861514dba9
No known key found for this signature in database
GPG key ID: DDC049DDA35585B6
7 changed files with 69 additions and 23 deletions

View file

@ -12,7 +12,18 @@ class EditableChamp::CarteComponent < EditableChamp::EditableChampBaseComponent
champ_id: @champ.input_id, champ_id: @champ.input_id,
url: update_path, url: update_path,
adresse_source: data_sources_data_source_adresse_path, adresse_source: data_sources_data_source_adresse_path,
options: @champ.render_options options: @champ.render_options,
translations: {
address_input_label: t(".address_input_label"),
address_input_description: t(".address_input_description"),
pin_input_label: t(".pin_input_label"),
pin_input_description: t(".pin_input_description"),
show_pin: t(".show_pin"),
add_pin: t(".add_pin"),
add_file: t(".add_file"),
choose_file: t(".choose_file"),
delete_file: t(".delete_file")
}
} }
end end

View file

@ -0,0 +1,11 @@
---
en:
address_input_label: "Find an address"
address_input_description: "Enter at least 2 characters"
pin_input_label: "Add a point to the map"
pin_input_description: "Example: "
show_pin: "Show your location on the map"
add_pin: "Add the point with the coordinates entered on the map"
add_file: "Add a GPX or KML file"
choose_file: "Choose a GPX or KML file"
delete_file: "Delete the file"

View file

@ -0,0 +1,11 @@
---
fr:
address_input_label: "Rechercher une adresse"
address_input_description: "Saisissez au moins 2 caractères"
pin_input_label: "Ajouter un point sur la carte"
pin_input_description: "Exemple : "
show_pin: "Afficher votre position sur la carte"
add_pin: "Ajouter le point avec les coordonnées saisies sur la carte"
add_file: "Ajouter un fichier GPX ou KML"
choose_file: "Choisir un fichier GPX ou KML"
delete_file: "Supprimer le fichier"

View file

@ -6,11 +6,13 @@ import { RemoteComboBox } from '../../ComboBox';
export function AddressInput({ export function AddressInput({
source, source,
featureCollection, featureCollection,
champId champId,
translations
}: { }: {
source: string; source: string;
featureCollection: FeatureCollection; featureCollection: FeatureCollection;
champId: string; champId: string;
translations: Record<string, string>;
}) { }) {
return ( return (
<div style={{ marginBottom: '10px' }}> <div style={{ marginBottom: '10px' }}>
@ -18,8 +20,8 @@ export function AddressInput({
minimumInputLength={2} minimumInputLength={2}
id={champId} id={champId}
loader={source} loader={source}
label="Rechercher une Adresse" label={translations.address_input_label}
description="Saisissez au moins 2 caractères" description={translations.address_input_description}
onChange={(item) => { onChange={(item) => {
if (item && item.data) { if (item && item.data) {
fire(document, 'map:zoom', { fire(document, 'map:zoom', {

View file

@ -9,11 +9,13 @@ import { CreateFeatures, DeleteFeatures } from '../hooks';
export function ImportFileInput({ export function ImportFileInput({
featureCollection, featureCollection,
createFeatures, createFeatures,
deleteFeatures deleteFeatures,
translations
}: { }: {
featureCollection: FeatureCollection; featureCollection: FeatureCollection;
createFeatures: CreateFeatures; createFeatures: CreateFeatures;
deleteFeatures: DeleteFeatures; deleteFeatures: DeleteFeatures;
translations: Record<string, string>;
}) { }) {
const { inputs, addInputFile, removeInputFile, onFileChange } = const { inputs, addInputFile, removeInputFile, onFileChange } =
useImportFiles(featureCollection, { createFeatures, deleteFeatures }); useImportFiles(featureCollection, { createFeatures, deleteFeatures });
@ -24,14 +26,14 @@ export function ImportFileInput({
className="fr-btn fr-btn--secondary fr-btn--icon-left fr-icon-add-circle-line" className="fr-btn fr-btn--secondary fr-btn--icon-left fr-icon-add-circle-line"
onClick={addInputFile} onClick={addInputFile}
> >
Ajouter un fichier GPX ou KML {translations.add_file}
</button> </button>
<div> <div>
{inputs.map((input) => ( {inputs.map((input) => (
<div key={input.id}> <div key={input.id}>
<input <input
title="Choisir un fichier gpx ou kml" title={translations.choose_file}
style={{ marginTop: '15px' }} className="fr-mt-2w"
id={input.id} id={input.id}
type="file" type="file"
accept=".gpx, .kml" accept=".gpx, .kml"
@ -40,7 +42,7 @@ export function ImportFileInput({
/> />
{input.hasValue && ( {input.hasValue && (
<span <span
title="Supprimer le fichier" title={translations.delete_file}
className="fr-icon-delete-line fr-text-default--error" className="fr-icon-delete-line fr-text-default--error"
style={{ style={{
cursor: 'pointer' cursor: 'pointer'

View file

@ -4,9 +4,11 @@ import type { Feature, FeatureCollection } from 'geojson';
import CoordinateInput from 'react-coordinate-input'; import CoordinateInput from 'react-coordinate-input';
export function PointInput({ export function PointInput({
featureCollection featureCollection,
translations
}: { }: {
featureCollection: FeatureCollection; featureCollection: FeatureCollection;
translations: Record<string, string>;
}) { }) {
const inputId = useId(); const inputId = useId();
const [value, setValue] = useState(''); const [value, setValue] = useState('');
@ -35,9 +37,10 @@ export function PointInput({
return ( return (
<div className="fr-input-group fr-mt-3w"> <div className="fr-input-group fr-mt-3w">
<label className="fr-label" htmlFor={inputId}> <label className="fr-label" htmlFor={inputId}>
Ajouter un point sur la carte {translations.pin_input_label}
<span className="fr-hint-text"> <span className="fr-hint-text">
Exemple : 43°48&#39;06&#34;N 006°14&#39;59&#34;E {translations.pin_input_description}
43°48&#39;06&#34;N 006°14&#39;59&#34;E
</span> </span>
</label> </label>
<div className="flex flex-gap-1 fr-mt-1w"> <div className="flex flex-gap-1 fr-mt-1w">
@ -46,11 +49,9 @@ export function PointInput({
type="button" type="button"
className="fr-btn fr-btn--secondary fr-icon-map-pin-2-line" className="fr-btn fr-btn--secondary fr-icon-map-pin-2-line"
onClick={getCurrentPosition} onClick={getCurrentPosition}
title="Afficher votre position sur la carte" title={translations.show_pin}
> >
<span className="sr-only"> <span className="sr-only">{translations.show_pin}</span>
Afficher votre position sur la carte
</span>
</button> </button>
) : null} ) : null}
<CoordinateInput <CoordinateInput
@ -78,11 +79,9 @@ export function PointInput({
className="fr-btn fr-icon-add-circle-line" className="fr-btn fr-icon-add-circle-line"
onClick={addPoint} onClick={addPoint}
disabled={!feature} disabled={!feature}
title="Ajouter le point avec les coordonnées saisies sur la carte" title={translations.add_pin}
> >
<span className="sr-only"> <span className="sr-only">{translations.add_pin}</span>
Ajouter le point avec les coordonnées saisies sur la carte
</span>
</button> </button>
</div> </div>
</div> </div>

View file

@ -16,13 +16,15 @@ export default function MapEditor({
url, url,
adresseSource, adresseSource,
options, options,
champId champId,
translations
}: { }: {
featureCollection: FeatureCollection; featureCollection: FeatureCollection;
url: string; url: string;
adresseSource: string; adresseSource: string;
options: { layers: string[] }; options: { layers: string[] };
champId: string; champId: string;
translations: Record<string, string>;
}) { }) {
const [cadastreEnabled, setCadastreEnabled] = useState(false); const [cadastreEnabled, setCadastreEnabled] = useState(false);
@ -35,11 +37,16 @@ export default function MapEditor({
<> <>
{error && <FlashMessage message={error} level="alert" fixed={true} />} {error && <FlashMessage message={error} level="alert" fixed={true} />}
<ImportFileInput featureCollection={featureCollection} {...actions} /> <ImportFileInput
featureCollection={featureCollection}
translations={translations}
{...actions}
/>
<AddressInput <AddressInput
source={adresseSource} source={adresseSource}
champId={champId} champId={champId}
featureCollection={featureCollection} featureCollection={featureCollection}
translations={translations}
/> />
<MapLibre layers={options.layers}> <MapLibre layers={options.layers}>
@ -57,7 +64,10 @@ export default function MapEditor({
/> />
) : null} ) : null}
</MapLibre> </MapLibre>
<PointInput featureCollection={featureCollection} /> <PointInput
featureCollection={featureCollection}
translations={translations}
/>
</> </>
); );
} }