commit a2bfaf2cc797c8a7e8943cb3733e9877a0dfa82c parent b40e06ba7a14525888d67be271a4cb0dfa49a57d Author: triesap <137732411+triesap@users.noreply.github.com> Date: Fri, 7 Mar 2025 09:55:53 +0000 apps-lib: refactor library to use parameterized i18n translation function and locale stores Diffstat:
34 files changed, 260 insertions(+), 958 deletions(-)
diff --git a/apps-lib/package.json b/apps-lib/package.json @@ -50,11 +50,10 @@ "@nostr-dev-kit/ndk": "^2.11.0", "@nostr-dev-kit/ndk-cache-dexie": "^2.5.9", "@nostr-dev-kit/ndk-svelte": "^2.4.0", + "@radroots/locales": "workspace:*", "@radroots/theme": "workspace:*", "@radroots/util": "workspace:*", "svelte-maplibre": "workspace:*", - "@sveltekit-i18n/base": "^1.3.7", - "@sveltekit-i18n/parser-icu": "^1.0.8", "luxon": "^3.5.0", "sveltekit-search-params": "^3.0.0" } diff --git a/apps-lib/src/lib/components/form/form-entry-price-quantity.svelte b/apps-lib/src/lib/components/form/form-entry-price-quantity.svelte @@ -6,7 +6,6 @@ LayoutTrellisLine, lib_fmt_price, lib_parse_currency_marker, - lls, Select, } from "$root"; import { @@ -15,10 +14,14 @@ num_str, type ElementCallbackValue, type FormField, + type I18nTranslateFunction, + type I18nTranslateLocale, } from "@radroots/util"; let { basis, + ls, + locale, val_input_price = $bindable(``), val_sel_currency = $bindable(``), val_sel_qty_unit = $bindable(``), @@ -28,6 +31,8 @@ input_field?: FormField; callback_input: ElementCallbackValue; }; + ls: I18nTranslateFunction; + locale: I18nTranslateLocale; val_input_price: string; val_sel_currency: string; val_sel_qty_unit: string; @@ -39,7 +44,7 @@ <LayoutTrellisLine basis={{ label: { - value: `${$lls(`icu.*_price`, { value: `${$lls(`common.product`)}` })} (${val_sel_currency}/${`${$lls(`measurement.mass.unit.${val_sel_qty_unit}_ab`)}`})`, + value: `${$ls(`icu.*_price`, { value: `${$ls(`common.product`)}` })} (${val_sel_currency}/${`${$ls(`measurement.mass.unit.${val_sel_qty_unit}_ab`)}`})`, }, }} > @@ -61,7 +66,7 @@ { entries: fiat_currencies.map((i) => ({ value: `${i}`, - label: lib_parse_currency_marker(i), + label: lib_parse_currency_marker($locale, i), })), }, ], @@ -74,14 +79,16 @@ id: id ? fmt_id(`${id}_input_price`) : undefined, layer: 1, sync: true, - placeholder: `${$lls(`icu.enter_the_*`, { value: `${$lls(`common.price`)}`.toLowerCase() })}`, + placeholder: `${$ls(`icu.enter_the_*`, { value: `${$ls(`common.price`)}`.toLowerCase() })}`, field: basis.input_field, callback: basis.callback_input, callback_blur: async ({ el }) => { if (!el.value) return; - el.value = lib_fmt_price(el.value, val_sel_currency).slice( - 1, - ); + el.value = lib_fmt_price( + $locale, + el.value, + val_sel_currency, + ).slice(1); //@todo fmt handles 'en' only }, }} @@ -102,7 +109,7 @@ { entries: mass_units.map((i) => ({ value: i, - label: `${$lls(`measurement.mass.unit.${i}_ab`)}`.toLowerCase(), + label: `${$ls(`measurement.mass.unit.${i}_ab`)}`.toLowerCase(), })), }, ], diff --git a/apps-lib/src/lib/components/form/form-entry-price.svelte b/apps-lib/src/lib/components/form/form-entry-price.svelte @@ -6,7 +6,6 @@ LayoutTrellisLine, lib_fmt_price, lib_parse_currency_marker, - lls, Select, } from "$root"; import { @@ -14,11 +13,15 @@ form_fields, mass_units, type ElementCallbackValue, + type I18nTranslateFunction, + type I18nTranslateLocale, type IIdOpt, } from "@radroots/util"; let { basis, + ls, + locale, val_input_price = $bindable(``), val_sel_currency = $bindable(``), val_sel_quantity_unit = $bindable(``), @@ -29,6 +32,8 @@ input_placeholder?: string; callback_input?: ElementCallbackValue; }; + ls: I18nTranslateFunction; + locale: I18nTranslateLocale; val_input_price: string; val_sel_currency: string; val_sel_quantity_unit: string; @@ -61,9 +66,11 @@ callback: basis.callback_input, callback_blur: async ({ el }) => { if (!el.value) return; - el.value = lib_fmt_price(el.value, val_sel_currency).slice( - 1, - ); + el.value = lib_fmt_price( + $locale, + el.value, + val_sel_currency, + ).slice(1); //@todo fmt handles 'en' only }, }} @@ -83,7 +90,7 @@ entries: fiat_currencies.map((i) => ({ value: i, label: basis.display_symbol - ? lib_parse_currency_marker(i) + ? lib_parse_currency_marker($locale, i) : i.toUpperCase(), })), }, @@ -107,7 +114,7 @@ { entries: mass_units.map((i) => ({ value: i, - label: `${$lls(`measurement.mass.unit.${i}_ab`)}`.toLowerCase(), + label: `${$ls(`measurement.mass.unit.${i}_ab`)}`.toLowerCase(), })), }, ], diff --git a/apps-lib/src/lib/components/form/form-entry-quantity.svelte b/apps-lib/src/lib/components/form/form-entry-quantity.svelte @@ -1,21 +1,16 @@ <script lang="ts"> - import { - EntryWrap, - fmt_id, - Input, - LayoutTrellisLine, - lls, - Select, - } from "$root"; + import { EntryWrap, fmt_id, Input, LayoutTrellisLine, Select } from "$root"; import { form_fields, mass_units, type ElementCallbackValue, + type I18nTranslateFunction, type IIdOpt, } from "@radroots/util"; let { basis, + ls, val_input_quantity = $bindable(``), val_sel_quantity_unit = $bindable(``), val_sel_quantity_label = $bindable(``), @@ -26,6 +21,7 @@ input_placeholder?: string; callback_input?: ElementCallbackValue; }; + ls: I18nTranslateFunction; val_input_quantity: string; val_sel_quantity_unit: string; val_sel_quantity_label: string; @@ -72,7 +68,7 @@ { entries: mass_units.map((i) => ({ value: i, - label: `${$lls(`measurement.mass.unit.${i}_ab`)}`.toLowerCase(), + label: `${$ls(`measurement.mass.unit.${i}_ab`)}`.toLowerCase(), })), }, ], @@ -91,7 +87,7 @@ entries: [ { value: `bag`, - label: `${$lls(`common.bag`)}`.toLowerCase(), + label: `${$ls(`common.bag`)}`.toLowerCase(), }, ], }, diff --git a/apps-lib/src/lib/components/form/form-entry-select-input.svelte b/apps-lib/src/lib/components/form/form-entry-select-input.svelte @@ -1,20 +1,16 @@ <script lang="ts"> - import { - EntryLine, - EntrySelect, - fmt_id, - LayoutTrellisLine, - lls, - } from "$root"; + import { EntryLine, EntrySelect, fmt_id, LayoutTrellisLine } from "$root"; import { type CallbackPromiseGeneric, type ElementCallbackSelect, type FormField, + type I18nTranslateFunction, type ISelectOption, } from "@radroots/util"; let { basis, + ls, val_sel = $bindable(``), val_sel_input = $bindable(``), }: { @@ -28,6 +24,7 @@ input_field?: FormField; entry_label?: string; }; + ls: I18nTranslateFunction; val_sel: string; val_sel_input: string; } = $props(); @@ -41,7 +38,7 @@ notify: basis.visible_input ? { label: { - value: `${$lls(`common.close`)}`, + value: `${$ls(`common.close`)}`, }, callback: async () => { await basis.callback_visible(false); diff --git a/apps-lib/src/lib/components/map/map-marker-area.svelte b/apps-lib/src/lib/components/map/map-marker-area.svelte @@ -1,11 +1,11 @@ <script lang="ts"> import { MapMarkerAreaDisplay } from "$root"; - import { Marker, Popup } from "svelte-maplibre"; import { type GeocoderReverseResult, type GeolocationPoint, type IMapMarkerArea, } from "@radroots/util"; + import { Marker, Popup } from "svelte-maplibre"; let { basis, diff --git a/apps-lib/src/lib/components/map/map.svelte b/apps-lib/src/lib/components/map/map.svelte @@ -1,8 +1,8 @@ <script lang="ts"> import { app_thc } from "$lib/store/app"; - import { MapLibre } from "svelte-maplibre"; import { cfg_map, fmt_cl, type IClOpt } from "@radroots/util"; import type { Snippet } from "svelte"; + import { MapLibre } from "svelte-maplibre"; let { basis = undefined, diff --git a/apps-lib/src/lib/components/trellis/trellis.svelte b/apps-lib/src/lib/components/trellis/trellis.svelte @@ -1,7 +1,6 @@ <script lang="ts"> import { app_lo, - lls, TrellisDefaultLabel, TrellisInput, TrellisOffset, @@ -9,7 +8,12 @@ TrellisTitle, TrellisTouch, } from "$root"; - import { fmt_cl, parse_layer, type ITrellis } from "@radroots/util"; + import { + fmt_cl, + parse_layer, + type I18nTranslateFunction, + type ITrellis, + } from "@radroots/util"; import type { Snippet } from "svelte"; let { @@ -17,11 +21,13 @@ el_default, el_offset, el_append, + ls, }: { basis: ITrellis; el_default?: Snippet; el_offset?: Snippet; el_append?: Snippet; + ls: I18nTranslateFunction; } = $props(); const hide_border_t = $derived( @@ -80,7 +86,7 @@ ? basis.default_el.labels : [ { - label: `${$lls(`common.no_items_to_display`)}.`, + label: `${$ls(`common.no_items_to_display`)}.`, }, ]} /> diff --git a/apps-lib/src/lib/components/upload/image-upload-add-photo.svelte b/apps-lib/src/lib/components/upload/image-upload-add-photo.svelte @@ -1,15 +1,20 @@ <script lang="ts"> - import { Glyph, lls } from "$root"; - import type { LcPhotoAddCallback } from "@radroots/util"; + import { Glyph } from "$root"; + import type { + I18nTranslateFunction, + LcPhotoAddCallback, + } from "@radroots/util"; let { basis, + ls, photo_path = $bindable(``), }: { basis: { lc_handle_photo_add: LcPhotoAddCallback; }; photo_path: string; + ls: I18nTranslateFunction; } = $props(); </script> @@ -34,7 +39,7 @@ <p class={`font-arch font-[600] text-sm text-layer-0-glyph capitalize`} > - {`${$lls(`icu.add_*`, { value: `${$lls(`common.photo`)}` })}`} + {`${$ls(`icu.add_*`, { value: `${$ls(`common.photo`)}` })}`} </p> </div> </button> diff --git a/apps-lib/src/lib/features/farm/farms-add-casli-detail.svelte b/apps-lib/src/lib/features/farm/farms-add-casli-detail.svelte @@ -1,6 +1,10 @@ <script lang="ts"> - import { CarouselItem, FormLineLedger, lls } from "$root"; - import { area_units, form_fields } from "@radroots/util"; + import { CarouselItem, FormLineLedger } from "$root"; + import { + area_units, + form_fields, + type I18nTranslateFunction, + } from "@radroots/util"; let { val_farmname = $bindable(``), @@ -9,6 +13,7 @@ val_farmcontact = $bindable(``), farm_geop_lat, farm_geop_lng, + ls, }: { val_farmname: string; val_farmarea: string; @@ -16,6 +21,7 @@ val_farmcontact: string; farm_geop_lat: string; farm_geop_lng: string; + ls: I18nTranslateFunction; } = $props(); </script> @@ -26,7 +32,7 @@ <FormLineLedger basis={{ id: `farm_location`, - label: `${$lls(`common.farm_location`)}`, + label: `${$ls(`common.farm_location`)}`, display_value: `${farm_geop_lat}, ${farm_geop_lng}`, }} /> @@ -34,9 +40,9 @@ bind:value={val_farmname} basis={{ id: `farm_name`, - label: `${$lls(`common.farm_name`)}`, + label: `${$ls(`common.farm_name`)}`, input: { - placeholder: `${$lls(`icu.enter_*`, { value: `${$lls(`common.farm_name`)}`.toLowerCase() })}`, + placeholder: `${$ls(`icu.enter_*`, { value: `${$ls(`common.farm_name`)}`.toLowerCase() })}`, }, }} /> @@ -45,16 +51,16 @@ bind:value_label_sel={val_farmarea_unit} basis={{ id: `farm_size`, - label: `${$lls(`common.farm_size`)}`, + label: `${$ls(`common.farm_size`)}`, label_select: { - label: `${$lls(`measurement.area.${val_farmarea_unit}_ab`)}`, + label: `${$ls(`measurement.area.${val_farmarea_unit}_ab`)}`, entries: area_units.map((i) => ({ value: i, - label: `${$lls(`measurement.area.${i}`)}`, + label: `${$ls(`measurement.area.${i}`)}`, })), }, input: { - placeholder: `${`${$lls(`icu.enter_*`, { value: `${$lls(`common.farm_size`)}`.toLowerCase() })}`} ${`${$lls(`measurement.area.${val_farmarea_unit}_pl`)}`.toLowerCase()}`, + placeholder: `${`${$ls(`icu.enter_*`, { value: `${$ls(`common.farm_size`)}`.toLowerCase() })}`} ${`${$ls(`measurement.area.${val_farmarea_unit}_pl`)}`.toLowerCase()}`, field: form_fields.farm_size, }, }} @@ -63,9 +69,9 @@ bind:value={val_farmcontact} basis={{ id: `farm_contact`, - label: `${$lls(`common.farm_contact`)}`, + label: `${$ls(`common.farm_contact`)}`, input: { - placeholder: `${$lls(`icu.enter_*`, { value: `${$lls(`common.contact_name`)}`.toLowerCase() })}`, + placeholder: `${$ls(`icu.enter_*`, { value: `${$ls(`common.contact_name`)}`.toLowerCase() })}`, }, }} /> diff --git a/apps-lib/src/lib/features/farm/farms-display-li-el.svelte b/apps-lib/src/lib/features/farm/farms-display-li-el.svelte @@ -1,5 +1,5 @@ <script lang="ts"> - import { liblocale, lls, Map, MapMarkerArea } from "$root"; + import { Map, MapMarkerArea } from "$root"; import { geol_lat_fmt, geol_lng_fmt, @@ -8,6 +8,8 @@ parse_tup_geop_point, type CallbackPromiseGeneric, type GeolocationPointTuple, + type I18nTranslateFunction, + type I18nTranslateLocale, type LcGeocodeCallback, type ResolveFarmInfo, } from "@radroots/util"; @@ -17,10 +19,14 @@ basis, lc_geocode, lc_handle_farm_view, + ls, + locale, }: { basis: ResolveFarmInfo; lc_geocode: LcGeocodeCallback; lc_handle_farm_view: CallbackPromiseGeneric<string>; + ls: I18nTranslateFunction; + locale: I18nTranslateLocale; } = $props(); let map: maplibregl.Map | undefined = $state(undefined); @@ -48,7 +54,7 @@ ? geol_lat_fmt( basis.geolocation.point.coordinates[1], `dms`, - $liblocale, + $locale, 3, ) : ``, @@ -59,7 +65,7 @@ ? geol_lng_fmt( basis.geolocation.point.coordinates[0], `dms`, - $liblocale, + $locale, 3, ) : ``, @@ -82,7 +88,7 @@ class={`flex flex-row h-6 px-2 py-1 justify-center items-center bg-lime-400 rounded-lg`} > <p class={`font-sans font-[700] text-white`}> - {`${$lls(`common.farm`)}`} + {`${$ls(`common.farm`)}`} </p> </div> </div> diff --git a/apps-lib/src/lib/features/farm/farms-products-review-card.svelte b/apps-lib/src/lib/features/farm/farms-products-review-card.svelte @@ -1,22 +1,22 @@ <script lang="ts"> - import { - app_lo, - Glyph, - ImagePath, - lib_parse_currency_marker, - lls, - } from "$root"; + import { app_lo, Glyph, ImagePath, lib_parse_currency_marker } from "$root"; import { ascii, + type I18nTranslateFunction, + type I18nTranslateLocale, type IViewFarmsProductsAddSubmission, } from "@radroots/util"; let { basis, + ls, + locale, }: { basis: { data: IViewFarmsProductsAddSubmission | undefined; }; + ls: I18nTranslateFunction; + locale: I18nTranslateLocale; } = $props(); //@todo @@ -65,13 +65,13 @@ class={`flex flex-row gap-[2px] justify-start items-center`} > <p class={`font-sans font-[600] text-xl text-th-black`}> - {`${lib_parse_currency_marker(basis.data.price_currency)}${basis.data.price_amount}`} + {`${lib_parse_currency_marker($locale, basis.data.price_currency)}${basis.data.price_amount}`} </p> <p class={`font-sans font-[600] text-xl text-th-black`}> {`/`} </p> <p class={`font-sans font-[600] text-xl text-th-black`}> - {`${$lls(`measurement.mass.unit.${basis.data.price_quantity_unit}_ab`)}`} + {`${$ls(`measurement.mass.unit.${basis.data.price_quantity_unit}_ab`)}`} </p> </div> </div> @@ -90,7 +90,7 @@ <p class={`font-sans font-[600] text-lg text-layer-1-glyph`} > - {`${basis.data.quantity_amount} ${$lls(`measurement.mass.unit.${basis.data.quantity_unit}_ab`)} ${basis.data.quantity_label}`} + {`${basis.data.quantity_amount} ${$ls(`measurement.mass.unit.${basis.data.quantity_unit}_ab`)} ${basis.data.quantity_label}`} </p> </div> </div> diff --git a/apps-lib/src/lib/features/search/search-result-display.svelte b/apps-lib/src/lib/features/search/search-result-display.svelte @@ -1,8 +1,9 @@ <script lang="ts"> - import { Glyph, lls, SearchResultContainer } from "$root"; + import { Glyph, SearchResultContainer } from "$root"; import { ascii, type CallbackPromiseGeneric, + type I18nTranslateFunction, type ResolveGeolocationInfo, type ResolveProfileInfo, type SearchServiceResult, @@ -10,6 +11,7 @@ let { basis, + ls, }: { basis: { result: SearchServiceResult; @@ -19,6 +21,7 @@ id: string; }>; }; + ls: I18nTranslateFunction; } = $props(); </script> @@ -52,7 +55,7 @@ <p class={`font-sans font-[900] text-[0.7rem] text-white uppercase`} > - {`${$lls(`common.location`)}`} + {`${$ls(`common.location`)}`} </p> </div> <p @@ -68,7 +71,7 @@ <p class={`font-sans font-[900] text-[0.7rem] text-white uppercase`} > - {`${$lls(`common.farm_land`)}`} + {`${$ls(`common.farm_land`)}`} </p> </div> {/if} @@ -122,7 +125,7 @@ <p class={`font-sans font-[900] text-[0.7rem] text-white uppercase`} > - {`${$lls(`common.profile`)}`} + {`${$ls(`common.profile`)}`} </p> </div> <p @@ -137,7 +140,7 @@ class={`font-sans font-[900] text-[0.7rem] text-white uppercase`} > {#if basis.result.result_k === `name`} - {`${$lls(`common.name`)}`} + {`${$ls(`common.name`)}`} {:else} {`@todo`} {/if} @@ -193,7 +196,7 @@ <p class={`font-sans font-[900] text-[0.7rem] text-white uppercase`} > - {`${$lls(`common.relay`)}`} + {`${$ls(`common.relay`)}`} </p> </div> <p @@ -207,7 +210,7 @@ <p class={`font-sans font-[900] text-[0.7rem] text-white uppercase`} > - {`${$lls(`common.url`)}`} + {`${$ls(`common.url`)}`} </p> </div> </div> diff --git a/apps-lib/src/lib/index.ts b/apps-lib/src/lib/index.ts @@ -90,7 +90,6 @@ export { default as FarmsDisplayLiEl } from "./features/farm/farms-display-li-el export { default as FarmsProductsReviewCard } from "./features/farm/farms-products-review-card.svelte" export { default as SearchResultContainer } from "./features/search/search-result-container.svelte" export { default as SearchResultDisplay } from "./features/search/search-result-display.svelte" -export * from "./locale/i18n.js" export * from "./store/app.js" export * from "./store/client.js" export * from "./store/component.js" @@ -110,3 +109,4 @@ export { default as Notifications } from "./view/notifications.svelte" export { default as Profile } from "./view/profile.svelte" export { default as Search } from "./view/search.svelte" export { default as Settings } from "./view/settings.svelte" + diff --git a/apps-lib/src/lib/locale/en/common.json b/apps-lib/src/lib/locale/en/common.json @@ -1,178 +0,0 @@ -{ - "farm_name": "Farm name", - "farm_contact": "Farm contact", - "farm_location": "Farm location", - "farm_size": "Farm size", - "contact_name": "Contact name", - "describe_your_product": "Describe your product", - "add_from_existing": "Add from existing", - "create_product": "Create product", - "logout": "Logout", - "farms": "Farms", - "loading": "Loading", - "disable_uploads": "Disable uploads", - "this_action_is_irreversible": "This action is irreversible", - "notifications": "Notifications", - "accept": "Accept", - "activation": "Activation", - "active": "Active", - "add": "Add", - "add_current_location": "Add current location", - "add_map_location": "Add map location", - "add_new": "Add new", - "add_new_location": "Add new location", - "agree": "Agree", - "all_accounts": "All accounts", - "area": "Area", - "at": "At", - "authenticated": "Authenticated", - "available_balance": "Available balance", - "back": "Back", - "bag": "Bag", - "bags": "Bags", - "bank_account": "Bank account", - "banner_photo": "Banner photo", - "bio": "Bio", - "business_name": "Business name", - "cancel": "Cancel", - "choose_a_profile_name": "Choose a profile name", - "climate": "Climate", - "close": "Close", - "color_mode": "Color mode", - "complete": "Complete", - "configure": "Configure", - "configure_your_device": "Configure your device", - "connect": "Connect", - "connected": "Connected", - "connection": "Connection", - "continue": "Continue", - "coordinates": "Coordinates", - "current_location": "Current location", - "dark": "Dark", - "date_created": "Date created", - "date_modified": "Date modified", - "delete": "Delete", - "description": "Description", - "details": "Details", - "device": "Device", - "disagree": "Disagree", - "disconnect": "Disconnect", - "do_you_want_to_continue_q": "Do you want to continue?", - "done": "Done", - "edit": "Edit", - "elevation": "Elevation", - "end_date": "End date", - "endpoint": "Endpoint", - "estate": "Estate", - "failure_to_process_the_request": "Failure to process the request", - "farm": "Farm", - "farm_land": "Farm land", - "file_name": "File name", - "file_size": "File size", - "filters": "Filters", - "from": "From", - "general": "General", - "hex": "Hex", - "highest_price": "Highest price", - "home": "Home", - "inbox": "Inbox", - "inflows": "Inflows", - "items": "Items", - "key": "Key", - "keypair": "Keypair", - "keys": "Keys", - "land_area": "Land area", - "land_plot": "Land plot", - "latitude": "Latitude", - "light": "Light", - "list": "List", - "listing": "Listing", - "location": "Location", - "locations": "Locations", - "longitude": "Longitude", - "lot": "Lot", - "lot_name": "Lot name", - "lowest_price": "Lowest price", - "make_primary": "Make primary", - "map": "Map", - "market": "Market", - "message": "Message", - "messages": "Messages", - "month": "Month", - "month_to_date": "Month to date", - "name": "Name", - "name_of_farm_or_estate": "Name of farm or estate", - "new": "New", - "no": "No", - "no_items_to_display": "No items to display", - "no_locations_saved": "No locations saved", - "nostr": "Nostr", - "not_connected": "Not connected", - "npub": "Npub", - "nsec": "Nsec", - "optional": "Optional", - "options": "Options", - "options_list": "Options list", - "order": "Order", - "origin": "Origin", - "other": "Other", - "outflows": "Outflows", - "overview": "Overview", - "page": "Page", - "per": "Per", - "personal": "Personal", - "photo": "Photo", - "photo_hosting": "Photo hosting", - "photos": "Photos", - "post": "Post", - "preview": "Preview", - "price": "Price", - "process": "Process", - "product": "Product", - "product_location": "Product location", - "product_name": "Product name", - "products": "Products", - "profile": "Profile", - "profile_name": "Profile name", - "profile_photo": "Profile photo", - "profiles": "Profiles", - "public_key": "Public key", - "publish": "Publish", - "quantity": "Quantity", - "quit": "Quit", - "reading": "Reading", - "relay": "Relay", - "relays": "Relays", - "reset": "Reset", - "return": "Return", - "review": "Review", - "search": "Search", - "secret_key": "Secret key", - "settings": "Settings", - "setup": "Setup", - "setup_for_farmer": "Setup for Farmer", - "skip": "Skip", - "socials": "Socials", - "soil": "Soil", - "start_date": "Start date", - "status": "Status", - "subject": "Subject", - "submit": "Submit", - "summary": "Summary", - "terms_of_use_agreement": "Terms of Use agreement", - "title": "Title", - "to": "To", - "unlock": "Unlock", - "update": "Update", - "upload_url": "Upload url", - "url": "url", - "username": "Username", - "using_public_key": "Using public key", - "value": "Value", - "view": "View", - "wallet": "Wallet", - "website": "Website", - "year": "Year", - "yes": "Yes", - "your_name": "Your name" -} -\ No newline at end of file diff --git a/apps-lib/src/lib/locale/en/farm.json b/apps-lib/src/lib/locale/en/farm.json @@ -1,15 +0,0 @@ -{ - "product": { - "validation": { - "key": { - "required": "Enter the product" - }, - "process": { - "required": "Enter the product process" - }, - "summary": { - "required": "Enter the product description" - } - } - } -} -\ No newline at end of file diff --git a/apps-lib/src/lib/locale/en/icu.json b/apps-lib/src/lib/locale/en/icu.json @@ -1,84 +0,0 @@ -{ - "*_as": "{value} as", - "*_available": "{value} Available", - "*_copied": "{value} copied", - "*_description": "{value} description", - "*_details": "{value} details", - "*_failure": "{value} failure", - "*_list": "{value} list", - "*_month": "{value} month", - "*_name": "{value} name", - "*_order": "{value} order", - "*_price": "{value} price", - "*_quantity": "{value} quantity", - "*_sold": "{value} sold", - "*_summary": "{value} summary", - "*_the": "{value} the", - "*_title": "{value} title", - "*_total": "{value} total", - "*_your_device": "{value} your device", - "a_*_is_required": "A {value} is required", - "add_*": "Add {value}", - "add_a_*": "Add a {value}", - "add_existing_*": "Add existing {value}", - "as_*": "As {value}", - "choose_*": "Choose {value}", - "choose_a_*": "Choose a {}", - "choose_on_*": "Choose on {value}", - "click_to_*": "Click to {value}", - "click_to_add_a_*": "Click to add a {value}", - "configure_*": "Configure {value}", - "connect_*": "Connect {value}", - "connected_*": "Connected {value}", - "create_new_*": "Create new {value}", - "default_*": "Default {value}", - "delete_*": "Delete {value}", - "disconnect_*": "Disconnect {value}", - "edit_*": "Edit {value}", - "enter_*": "Enter {value}", - "enter_*_per_order": "Enter {value} per order", - "enter_a_*": "Enter a {value}", - "enter_new_*": "Enter new {value}", - "enter_the_*": "Enter the {value}", - "error_loading_*": "Error loading {value}", - "failure_*": "Failure {value}", - "failure_saving_*_to_the_database": "Failure saving {value} to the database", - "go_*": "Go {value}", - "invalid_*": "Invalid {value}", - "invalid_*_entry": "Invalid {value} entry", - "last_*": "Last {value}", - "listing_*": "Listing {value}", - "month_of_*": "Month of {value}", - "name_your_*": "Name your {value}", - "new_*": "New {value}", - "no_*": "No {value}", - "no_*_published": "No {value} published", - "no_*_selected": "No {value} selected", - "no_*_to_display": "No {value} to display", - "nostr_*": "Nostr {value}", - "post_*": "Post {value}", - "primary_*": "Primary {value}", - "reading_*": "Reading {value}", - "set_as_*": "Set as {value}", - "show_*": "Show {value}", - "the_*": "The {value}", - "the_*_is_available": "The {value} is available", - "the_*_is_incomplete": "The {value} is incomplete", - "the_*_is_missing": "The {value} is missing", - "the_*_is_registered": "The {value} is registered", - "the_*_is_required": "The {value} is missing", - "the_current_entry_*_will_be_deleted": "The current entry \"{value}\" will be deleted", - "the_listing_will_be_created_without_a_*": "The listing will be created without a {value}", - "there_was_a_failure_while_*": "There was a failure while {value}", - "this_*": "This {value}", - "toggle_*": "Toggle {value}", - "total_*": "Total {value}", - "unable_to_save_*": "Unable to save {value}", - "unconnected_*": "Unconnected {value}", - "uploading_*_photos": "Uploading {value} photos", - "use_existing_*": "Use existing {value}", - "valid_*": "Valid {value}", - "view_*": "View {value}", - "view_the_*": "View the {value}", - "your_*": "Your {value}" -} -\ No newline at end of file diff --git a/apps-lib/src/lib/locale/en/measurement.json b/apps-lib/src/lib/locale/en/measurement.json @@ -1,38 +0,0 @@ -{ - "area": { - "ac": "Acre", - "ac_pl": "Acres", - "ac_ab": "Ac.", - "ha": "Hectare", - "ha_pl": "Hectares", - "ha_ab": "Ha.", - "m2": "Square metre", - "m2_pl": "Square metres", - "m2_ab": "Sq. M.", - "ft2": "Square foot", - "ft2_pl": "Square feet", - "ft2_ab": "Sq. Ft." - }, - "length": { - "ft": "Foot", - "ft_ab": "Ft.", - "m": "Metre", - "m_ab": "M." - }, - "mass": { - "unit": { - "g": "Gram", - "g_ab": "g.", - "g_pl": "Grams", - "hg": "100 Gram", - "hg_ab": "100g.", - "hg_pl": "100 Grams", - "kg": "Kilogram", - "kg_ab": "kg.", - "kg_pl": "Kilograms", - "lb": "Pound", - "lb_ab": "lb.", - "lb_pl": "Pounds" - } - } -} -\ No newline at end of file diff --git a/apps-lib/src/lib/locale/en/model.json b/apps-lib/src/lib/locale/en/model.json @@ -1,291 +0,0 @@ -{ - "location_gcs": { - "fields": { - "area": { - "label": "Location Area" - }, - "climate": { - "label": "Location Climate" - }, - "elevation": { - "label": "Location Elevation" - }, - "gc_admin1_id": { - "label": "Location Gc Admin1 Id" - }, - "gc_admin1_name": { - "label": "Location Gc Admin1 Name" - }, - "gc_country_id": { - "label": "Location Gc Country Id" - }, - "gc_country_name": { - "label": "Location Gc Country Name" - }, - "gc_id": { - "label": "Location Gc Id" - }, - "gc_name": { - "label": "Location Gc Name" - }, - "geohash": { - "label": "Location Geohash" - }, - "kind": { - "label": "Location Kind" - }, - "label": { - "label": "Location Label" - }, - "lat": { - "label": "Location Latitude" - }, - "lng": { - "label": "Location Latitude" - }, - "soil": { - "label": "Location Soil" - } - }, - "schema": { - "geohash.length": "The location geohash must be 9 characters", - "geohash.required": "The location geohash is required", - "kind.required": "The location kind is required", - "lat.max": "The location latitude must be less than 90", - "lat.min": "The location latitude must be greater than -90", - "lat.required": "The location latitude is required", - "lng.max": "The location latitude must be less than 180", - "lng.min": "The location latitude must be greater than -180", - "lng.required": "The location latitude is required" - } - }, - "log_error": { - "fields": { - "app_system": { - "label": "Log App System" - }, - "app_version": { - "label": "Log App Version" - }, - "cause": { - "label": "Log Cause" - }, - "data": { - "label": "Log Data" - }, - "error": { - "label": "Log Error" - }, - "message": { - "label": "Log Message" - }, - "nostr_pubkey": { - "label": "Log Nostr Pubkey" - }, - "stack_trace": { - "label": "Log Stack Trace" - } - }, - "schema": { - "app_system.required": "The log app system is required", - "app_version.required": "The log app version is required", - "error.required": "The log error is required", - "message.required": "The log message is required", - "nostr_pubkey.required": "The log nostr pubkey is required" - } - }, - "media_upload": { - "fields": { - "description": { - "label": "Description" - }, - "file_path": { - "label": "File Path" - }, - "label": { - "label": "Label" - }, - "mime_type": { - "label": "Mime Type" - }, - "res_base": { - "label": "Resource Endpoint" - }, - "res_path": { - "label": "Resource Path" - } - }, - "schema": { - "file_path.required": "The media file path is required", - "mime_type.required": "The media mime type is required", - "res_base.regex": "The media resource endpoint requires an http protocol", - "res_base.required": "The media resource endpoint is required", - "res_base.url": "The media resource endpoint is incorrectly formatted", - "res_path.required": "The media resource path is required" - } - }, - "nostr_profile": { - "fields": { - "about": { - "label": "Profile About" - }, - "banner": { - "label": "Profile Banner" - }, - "display_name": { - "label": "Profile Display Name" - }, - "lud06": { - "label": "Profile Lud-06" - }, - "lud16": { - "label": "Profile Lud-16" - }, - "name": { - "label": "Profile Name" - }, - "nip05": { - "label": "Profile Nip-05" - }, - "picture": { - "label": "Profile Picture" - }, - "public_key": { - "label": "Profile Public Key" - }, - "website": { - "label": "Profile Website" - } - }, - "schema": { - "banner.url": "The profile banner url is incomplete", - "nip05.email": "The profile nip-05 is incorrectly formatted", - "picture.url": "The profile picture url is incomplete", - "public_key.length": "The profile public key must be 64 characters", - "public_key.required": "The profile public key is required", - "website.url": "The profile website url is incomplete" - } - }, - "nostr_relay": { - "fields": { - "contact": { - "label": "Administrator Contact" - }, - "data": { - "label": "Additional Information" - }, - "description": { - "label": "Relay Description" - }, - "name": { - "label": "Relay Name" - }, - "pubkey": { - "label": "Administrator" - }, - "relay_id": { - "label": "Relay Id" - }, - "software": { - "label": "Software" - }, - "supported_nips": { - "label": "Supported Nips" - }, - "url": { - "label": "Relay Endpoint" - }, - "version": { - "label": "Software Version" - } - }, - "schema": { - "url.regex": "The relay relay endpoint requires a websocket protocol", - "url.required": "The relay relay endpoint is required", - "url.url": "The relay relay endpoint is incorrectly formatted" - } - }, - "trade_product": { - "fields": { - "category": { - "label": "Product Category" - }, - "key": { - "label": "Product Kind" - }, - "lot": { - "label": "Product Lot" - }, - "notes": { - "label": "Notes" - }, - "price_amt": { - "label": "Price Amount" - }, - "price_currency": { - "label": "Price Currency" - }, - "price_qty_amt": { - "label": "Price Quantity" - }, - "price_qty_unit": { - "label": "Price Quantity Unit" - }, - "process": { - "label": "Processing Method" - }, - "profile": { - "label": "Flavor Profile" - }, - "qty_amt": { - "label": "Quantity Amount" - }, - "qty_avail": { - "label": "Quantity Available" - }, - "qty_label": { - "label": "Quantity Name" - }, - "qty_unit": { - "label": "Quantity Unit" - }, - "summary": { - "label": "Product Description" - }, - "title": { - "label": "Product Title" - }, - "year": { - "label": "Production Year" - } - }, - "schema": { - "category.required": "The product category is required", - "key.required": "The product kind is required", - "lot.max": "The product lot must be less than 120 characters", - "lot.min": "The product lot must be more than 1 character", - "lot.required": "The product lot is required", - "price_amt.positive": "The product price amount must be positive", - "price_amt.required": "The product price amount is required", - "price_currency.length": "The product price currency must be 3 characters", - "price_currency.required": "The product price currency is required", - "price_qty_amt.int": "The product price quantity must be an integer", - "price_qty_amt.positive": "The product price quantity must be positive", - "price_qty_amt.required": "The product price quantity is required", - "price_qty_unit.required": "The product price quantity unit is required", - "process.required": "The product processing method is required", - "profile.required": "The product flavor profile is required", - "qty_amt.int": "The product quantity amount must be an integer", - "qty_amt.positive": "The product quantity amount must be positive", - "qty_amt.required": "The product quantity amount is required", - "qty_avail.int": "The product quantity available must be an integer", - "qty_avail.positive": "The product quantity available must be positive", - "qty_unit.required": "The product quantity unit is required", - "summary.required": "The product description is required", - "title.required": "The product title is required", - "year.int": "The product production year must be an integer", - "year.positive": "The product production year must be positive", - "year.required": "The product production year is required" - } - } -} -\ No newline at end of file diff --git a/apps-lib/src/lib/locale/en/trade.json b/apps-lib/src/lib/locale/en/trade.json @@ -1,118 +0,0 @@ -{ - "glossary": { - "lot": "Lot", - "process": "Process", - "profile": "Profile" - }, - "product": { - "fields": { - "price_amt": { - "err_invalid": "Enter the price" - } - }, - "default": { - "process": { - "natural": "Natural", - "dried": "Dried", - "roasted": "Roasted" - } - }, - "key": { - "cacao": { - "name": "Cacao", - "process": { - "chocolate": "Chocolate", - "cocoa_butter": "Cocoa Butter", - "cocoa_powder": "Cocoa Powder", - "dried": "Dried", - "fermented": "Fermented", - "raw": "Raw", - "roasted": "Roasted" - } - }, - "coffee": { - "name": "Coffee", - "process": { - "carbonic_maceration": "Carbonic Maceration", - "dry": "Dry", - "honey": "Honey", - "natural": "Natural", - "pulped_natural": "Pulped Natural", - "semi_washed": "Semi-Washed", - "washed": "Washed", - "wet_hulled": "Wet-Hulled" - }, - "profile": { - "apricot": "Apricot", - "banana": "Banana", - "bergamot": "Bergamot", - "berry": "Berry", - "black cherry": "Black Cherry", - "black currant": "Black Currant", - "black tea": "Black Tea", - "blueberry": "Blueberry", - "brown sugar": "Brown Sugar", - "caramel": "Caramel", - "cherry": "Cherry", - "chocolate": "Chocolate", - "cola": "Cola", - "cranberry": "Cranberry", - "ctrius": "Ctrius", - "dark chocolate": "Dark Chocolate", - "dried dates": "Dried Dates", - "dried fig": "Dried Fig", - "golden raisin": "Golden Raisin", - "grape": "Grape", - "grapefruit": "Grapefruit", - "green apple": "Green Apple", - "green grape": "Green Grape", - "green tea": "Green Tea", - "jasmine honeysuckle": "Jasmine Honeysuckle", - "lemon": "Lemon", - "licorice/anise": "Licorice/Anise", - "lychee": "Lychee", - "magnolia": "Magnolia", - "mandarin": "Mandarin", - "mango": "Mango", - "maple syrup": "Maple Syrup", - "marshmallow": "Marshmallow", - "milk chocolate": "Milk Chocolate", - "natural": "Natural", - "nectarine": "Nectarine", - "nougat": "Nougat", - "nut": "Nut", - "orange": "Orange", - "orange blossom": "Orange Blossom", - "peach": "Peach", - "pineapple": "Pineapple", - "plum": "Plum", - "prune": "Prune", - "raisin": "Raisin", - "raspberry": "Raspberry", - "red apple": "Red Apple", - "red currant": "Red Currant", - "red grape": "Red Grape", - "roses": "Roses", - "star fruit": "Star Fruit", - "stronefruit": "Stronefruit", - "sugar cane": "Sugar Cane", - "sweet bread pastry": "Sweet Bread Pastry", - "tamarind": "Tamarind", - "tropical fruit": "Tropical Fruit", - "vanilla": "Vanilla", - "white grape": "White Grape" - } - }, - "maca": { - "name": "Maca", - "process": { - "capsules": "Capsules", - "gelatinized": "Gelatinized", - "powdered": "Powdered", - "raw": "Raw", - "roasted": "Roasted" - } - } - } - } -} -\ No newline at end of file diff --git a/apps-lib/src/lib/locale/i18n.ts b/apps-lib/src/lib/locale/i18n.ts @@ -1,42 +0,0 @@ -import i18n from '@sveltekit-i18n/base'; -import type { Config } from '@sveltekit-i18n/parser-icu'; -import parser from '@sveltekit-i18n/parser-icu'; -import locales_keys from './locales.json'; - -type LanguageConfig = { - default?: string; - value?: string; -}; - -export type Locale = keyof typeof locales_keys; - -const libtranslations: Record<Locale, any> = { - en: { locales_keys }, -}; - -const config: Config<LanguageConfig> = { - initLocale: `en` satisfies Locale, - translations: libtranslations, - parser: parser(), - loaders: [ - ...Object.keys(libtranslations).map((locale) => [`common`, `farm`, `icu`, `measurement`, `model`, `trade`].map(key => ({ - locale, - key, - loader: async () => (await import(`./${locale}/${key}.json`)).default - }))), - ].flat() -}; - -const { - t: lls, - loading: libtranslations_loading, - locales: liblocales, - locale: liblocale, - loadTranslations: libload_translations -} = new i18n(config);; - -libtranslations_loading.subscribe(async (_loading) => { - if (_loading) await libtranslations_loading.toPromise(); -}); -export { libload_translations, liblocale, liblocales, libtranslations, libtranslations_loading, lls }; - diff --git a/apps-lib/src/lib/locale/locales.json b/apps-lib/src/lib/locale/locales.json @@ -1,3 +0,0 @@ -{ - "en": "English" -} -\ No newline at end of file diff --git a/apps-lib/src/lib/util/idb.ts b/apps-lib/src/lib/util/idb.ts @@ -2,53 +2,56 @@ import { browser } from "$app/environment"; import { fmt_id } from "$root"; //@ts-ignore -const kv_name = import.meta.env.VITE_PUBLIC_KV_NAME; -if (!kv_name) throw new Error('Error: VITE_PUBLIC_KV_NAME is required'); +const idb_name = import.meta.env.VITE_PUBLIC_IDB_NAME; +if (!idb_name) throw new Error('Error: VITE_PUBLIC_IDB_NAME is required'); export let idb: Keyva; -if (browser) idb = new Keyva({ name: kv_name }); +if (browser) idb = new Keyva({ name: idb_name }); -export const kv_init = async (): Promise<void> => { +export const idb_init = async (): Promise<void> => { if (!browser) return; const range = Keyva.prefix(`*`); - const kv_list = await idb.each({ range }, `keys`); - await Promise.all(kv_list.map((i) => idb.delete(i))); + const idb_list = await idb.each({ range }, `keys`); + console.log(`idb_list `, idb_list) + await Promise.all(idb_list.map((i) => idb.delete(i))); }; -export const kv_init_page = async (): Promise<void> => { +export const idb_init_page = async (): Promise<void> => { if (!browser) return; - const kv_pref = fmt_id(); - const range = Keyva.prefix(kv_pref); - const kv_list = await idb.each({ range }, `keys`); - await Promise.all(kv_list.map((i) => idb.delete(i))); + const idb_pref = fmt_id(); + const range = Keyva.prefix(idb_pref); + console.log(`idb_init_page range `, range) + const idb_list = await idb.each({ range }, `keys`); + console.log(`idb_list `, idb_list) + await Promise.all(idb_list.map((i) => idb.delete(i))); }; -export const kv_sync = async (list: [string, string][]): Promise<void> => { +export const idb_sync = async (list: [string, string][]): Promise<void> => { if (!browser) return; for (const [key, val] of list) await idb.set(key, val); }; -export class KvLib<T extends string> { - private _kv: Keyva; +export class IdbLib<T extends string> { + private _idb: Keyva; constructor(kv: Keyva) { - this._kv = kv; + this._idb = kv; } public init = async () => { - await kv_init_page(); + await idb_init_page(); } public save = async (key: T, value: string) => { - await this._kv.set(fmt_id(key), value); + await this._idb.set(fmt_id(key), value); } public read = async (key: T): Promise<string | undefined> => { - const result = await this._kv.get<string>(fmt_id(key)); + const result = await this._idb.get<string>(fmt_id(key)); if (result) return result; return undefined; } public del = async (key: T) => { - await this._kv.delete(fmt_id(key)); + await this._idb.delete(fmt_id(key)); } } \ No newline at end of file diff --git a/apps-lib/src/lib/util/lib.ts b/apps-lib/src/lib/util/lib.ts @@ -1,7 +1,7 @@ import { browser } from "$app/environment"; import { goto } from "$app/navigation"; import { page } from "$app/state"; -import { liblocale, win_h, win_w } from "$root"; +import { win_h, win_w } from "$root"; import type { ColorMode, ThemeKey } from "@radroots/theme"; import { encode_qp_route, fmt_geometry_point_coords, fmt_price, parse_currency_marker, type CallbackRoute, type GeometryPoint, type IErrorCatchCallback } from "@radroots/util"; import { get } from "svelte/store"; @@ -61,19 +61,16 @@ export const query_params_clear = async (): Promise<void> => { page.url && await goto(page.url.pathname, { replaceState: true }) }; -export const lib_fmt_price = (value: string, currency: string): string => { - const $locale = get_store(liblocale); - return fmt_price($locale, value, currency); +export const lib_fmt_price = (locale: string, value: string, currency: string): string => { + return fmt_price(locale, value, currency); }; -export const lib_parse_currency_marker = (currency: string): string => { - const $locale = get_store(liblocale); - return parse_currency_marker($locale, currency); +export const lib_parse_currency_marker = (locale: string, currency: string): string => { + return parse_currency_marker(locale, currency); }; -export const lib_fmt_geometry_point_coords = (point: GeometryPoint): string => { - const $locale = get_store(liblocale); - return fmt_geometry_point_coords(point, $locale); +export const lib_fmt_geometry_point_coords = (locale: string, point: GeometryPoint): string => { + return fmt_geometry_point_coords(point, locale); }; export const view_effect = <T extends string>(view: T): void => { diff --git a/apps-lib/src/lib/view/farms-add.svelte b/apps-lib/src/lib/view/farms-add.svelte @@ -14,8 +14,6 @@ Glyph, handle_err, LayoutView, - liblocale, - lls, PageToolbar, } from "$root"; import { @@ -29,6 +27,8 @@ type GeocoderReverseResult, type GeolocationAddress, type GeolocationPoint, + type I18nTranslateFunction, + type I18nTranslateLocale, type IViewFarmsAddSubmission, type LcGeocodeCallback, type LcGeocodeCurrentCallback, @@ -38,6 +38,8 @@ let { basis, + ls, + locale, }: { basis: { callback_route?: CallbackRoute<string>; @@ -48,6 +50,8 @@ data_s: IViewFarmsAddSubmission; }>; }; + ls: I18nTranslateFunction; + locale: I18nTranslateLocale; } = $props(); let loading = $state(false); @@ -71,11 +75,11 @@ }); const farm_geop_lat = $derived( - map_geop ? geol_lat_fmt(map_geop.lat, `dms`, $liblocale, 3) : ``, + map_geop ? geol_lat_fmt(map_geop.lat, `dms`, $locale, 3) : ``, ); const farm_geop_lng = $derived( - map_geop ? geol_lng_fmt(map_geop.lng, `dms`, $liblocale, 3) : ``, + map_geop ? geol_lng_fmt(map_geop.lng, `dms`, $locale, 3) : ``, ); const farm_geolocation_address: GeolocationAddress | undefined = $derived( @@ -149,7 +153,7 @@ <p class={`font-sans font-[600] text-lg text-layer-0-glyph`} > - {`${$lls(`common.back`)}`} + {`${$ls(`common.back`)}`} </p> </button> </Fade> @@ -161,7 +165,7 @@ }} > <p class={`font-sans font-[600] text-lg text-layer-0-glyph-hl`}> - {`${$lls(`common.details`)}`} + {`${$ls(`common.details`)}`} </p> <Glyph basis={{ @@ -191,6 +195,7 @@ bind:val_farmarea_unit {farm_geop_lat} {farm_geop_lng} + {ls} /> </Carousel> </LayoutView> @@ -199,12 +204,12 @@ <ButtonLayoutPair basis={{ continue: { - label: `${$lls(`common.continue`)}`, + label: `${$ls(`common.continue`)}`, disabled: disabled_submit, callback: handle_continue, }, back: { - label: `${$lls(`common.back`)}`, + label: `${$ls(`common.back`)}`, visible: $casl_i > 0, callback: handle_back, }, diff --git a/apps-lib/src/lib/view/farms-products-add.svelte b/apps-lib/src/lib/view/farms-products-add.svelte @@ -21,7 +21,6 @@ LayoutBottomButton, LayoutView, lib_fmt_geometry_point_coords, - lls, MapLocationSelectEnvelope, MarkerIndexedView, PageToolbar, @@ -50,6 +49,8 @@ type GeocoderReverseResult, type GeolocationAddress, type GeolocationPoint, + type I18nTranslateFunction, + type I18nTranslateLocale, type ISelectOption, type IViewBasis, type IViewFarmsProductsAddSubmission, @@ -92,6 +93,8 @@ let { basis, + ls, + locale, }: { basis: IViewBasis<{ data: ResolveFarmInfo; @@ -112,6 +115,8 @@ geolocation_id?: string; }>; }>; + ls: I18nTranslateFunction; + locale: I18nTranslateLocale; } = $props(); let loading_submit = $state(false); @@ -207,6 +212,7 @@ basis.data.geolocation.address, ) || lib_fmt_geometry_point_coords( + $locale, basis.data.geolocation.point, ) || ``, @@ -288,7 +294,7 @@ const geop = await basis.lc_geop_current(); if (!geop) { return void (await basis.lc_gui_alert( - `${$lls(`icu.failure_*`, { value: `${$lls(`icu.reading_*`, { value: `${$lls(`common.geocode`)}`.toLowerCase() })}` })}`, + `${$ls(`icu.failure_*`, { value: `${$ls(`icu.reading_*`, { value: `${$ls(`common.location`)}`.toLowerCase() })}` })}`, )); } const geoc = await basis.lc_geocode(geop); @@ -305,7 +311,7 @@ const val = await idb.get(fmt_id(kv_id)); if (!val) return void basis.lc_gui_alert( - `${$lls(`farm.product.validation.${kv_id}.required`)}`, + `${$ls(`farm.product.validation.${kv_id}.required`)}`, ); } await casl_inc(); @@ -388,7 +394,7 @@ <PageToolbar basis={{ header: { - label: `${`${$lls(`common.farm`)}`} / ${`${$lls(`common.product`)}`}`, + label: `${`${$ls(`common.farm`)}`} / ${`${$ls(`common.product`)}`}`, callback_route: basis.callback_route || { route: `/farms` }, }, }} @@ -398,8 +404,8 @@ <ButtonHorizontalPairSlide bind:toggle={toggle_opt_addexisting} basis={{ - label_l: `${$lls(`common.create_product`)}`, - label_r: `${$lls(`common.add_from_existing`)}`, + label_l: `${$ls(`common.create_product`)}`, + label_r: `${$ls(`common.add_from_existing`)}`, }} /> </div> @@ -412,8 +418,8 @@ loading: loading_submit, label: $casl_i === $casl_imax - ? `${$lls(`common.post`)}` - : `${$lls(`common.continue`)}`, + ? `${$ls(`common.post`)}` + : `${$ls(`common.continue`)}`, callback: async () => { handle_continue(); }, @@ -445,11 +451,12 @@ <FormEntrySelectInput bind:val_sel={product_key_sel} bind:val_sel_input={product_key_sel_input} + {ls} basis={{ id: `key`, - entry_label: `${$lls(`common.product`)}`, + entry_label: `${$ls(`common.product`)}`, visible_input: product_key_sel_toggle, - input_placeholder: `${$lls(`icu.enter_the_*`, { value: `${$lls(`icu.*_name`, { value: `${$lls(`common.product`)}` })}`.toLowerCase() })}`, + input_placeholder: `${$ls(`icu.enter_the_*`, { value: `${$ls(`icu.*_name`, { value: `${$ls(`common.product`)}` })}`.toLowerCase() })}`, input_field: form_fields.product_key, callback_visible: handle_tradepr_key_toggle, callback_select: async ({ value }) => @@ -457,16 +464,16 @@ select_entries: [ { value: ``, - label: `${$lls(`icu.choose_*`, { value: `${$lls(`common.product`)}`.toLowerCase() })}`, + label: `${$ls(`icu.choose_*`, { value: `${$ls(`common.product`)}`.toLowerCase() })}`, disabled: true, }, ...trade_keys.map((i) => ({ value: i, - label: `${$lls(`trade.product.key.${i}.name`)}`, + label: `${$ls(`trade.product.key.${i}.name`)}`, })), { value: `*other`, - label: `${$lls(`common.other`)}`, + label: `${$ls(`common.other`)}`, }, ], }} @@ -474,11 +481,12 @@ <FormEntrySelectInput bind:val_sel={product_process_sel} bind:val_sel_input={product_process_sel_input} + {ls} basis={{ id: `process`, - entry_label: `${$lls(`common.process`)}`, + entry_label: `${$ls(`common.process`)}`, visible_input: product_process_sel_toggle, - input_placeholder: `${$lls(`icu.enter_the_*`, { value: `${$lls(`common.process`)}`.toLowerCase() })}`, + input_placeholder: `${$ls(`icu.enter_the_*`, { value: `${$ls(`common.process`)}`.toLowerCase() })}`, input_field: form_fields.product_process, callback_visible: handle_product_process_toggle, callback_select: async ({ value }) => @@ -487,27 +495,27 @@ ? [ { value: ``, - label: `${$lls(`icu.choose_*`, { value: `${$lls(`common.process`)}`.toLowerCase() })}`, + label: `${$ls(`icu.choose_*`, { value: `${$ls(`common.process`)}`.toLowerCase() })}`, disabled: true, }, ...product_process_list.map((i) => ({ value: i, - label: `${$lls(`trade.product.key.${tradepr_key_parsed}.process.${i}`)}`, + label: `${$ls(`trade.product.key.${tradepr_key_parsed}.process.${i}`)}`, })), { value: `*other`, - label: `${$lls(`common.other`)}`, + label: `${$ls(`common.other`)}`, }, ] : [ { value: ``, - label: `${$lls(`icu.choose_*`, { value: `${$lls(`common.process`)}`.toLowerCase() })}`, + label: `${$ls(`icu.choose_*`, { value: `${$ls(`common.process`)}`.toLowerCase() })}`, disabled: true, }, { value: `*choose-product`, - label: `${$lls(`icu.choose_*`, { value: `${$lls(`common.product`)}`.toLowerCase() })}`, + label: `${$ls(`icu.choose_*`, { value: `${$ls(`common.product`)}`.toLowerCase() })}`, }, ].concat( product_key_sel === `*other` @@ -515,12 +523,12 @@ ...trade.default.process.map( (i) => ({ value: i, - label: `${$lls(`trade.product.default.process.${i}`)}`, + label: `${$ls(`trade.product.default.process.${i}`)}`, }), ), { value: `*other`, - label: `${$lls(`common.other`)}`, + label: `${$ls(`common.other`)}`, }, ] : [], @@ -531,9 +539,9 @@ bind:val={product_description_input} basis={{ id: `description`, - entry_label: `${$lls(`common.description`)}`, + entry_label: `${$ls(`common.description`)}`, field: form_fields.product_description, - placeholder: `${$lls(`common.describe_your_product`)}`, + placeholder: `${$ls(`common.describe_your_product`)}`, }} /> </CarouselItem> @@ -550,6 +558,8 @@ bind:val_input_price={product_price_input} bind:val_sel_currency={product_price_cur_sel} bind:val_sel_quantity_unit={product_price_qty_unit_sel} + {ls} + {locale} basis={{ id: `price`, entry_label: `price`, @@ -560,6 +570,7 @@ bind:val_input_quantity={product_quantity_input} bind:val_sel_quantity_unit={product_quantity_unit_sel} bind:val_sel_quantity_label={product_quantity_label_sel} + {ls} basis={{ id: `quantity`, entry_label: `quantity`, @@ -572,19 +583,19 @@ bind:val={product_location_sel} basis={{ id: `location`, - entry_label: `${$lls(`common.location`)}`, + entry_label: `${$ls(`common.location`)}`, callback: async ({ value }) => await handle_product_location_sel_map(value), entries: tradepr_lgc_map_geoc ? [ { value: ``, - label: `${$lls(`icu.choose_*`, { value: `${$lls(`common.location`)}`.toLowerCase() })}`, + label: `${$ls(`icu.choose_*`, { value: `${$ls(`common.location`)}`.toLowerCase() })}`, disabled: true, }, { value: `*map`, - label: `${$lls(`icu.choose_on_*`, { value: `${$lls(`common.map`)}`.toLowerCase() })}`, + label: `${$ls(`icu.choose_on_*`, { value: `${$ls(`common.map`)}`.toLowerCase() })}`, }, { value: `*map-location`, @@ -596,14 +607,14 @@ : [ { value: ``, - label: `${$lls(`icu.choose_*`, { value: `${$lls(`common.location`)}`.toLowerCase() })}`, + label: `${$ls(`icu.choose_*`, { value: `${$ls(`common.location`)}`.toLowerCase() })}`, disabled: true, }, ...entries_farm_location, ...entries_farm_lots_locations, { value: `*map`, - label: `${$lls(`icu.choose_on_*`, { value: `${$lls(`common.map`)}`.toLowerCase() })}`, + label: `${$ls(`icu.choose_on_*`, { value: `${$ls(`common.map`)}`.toLowerCase() })}`, }, ], }} @@ -615,6 +626,8 @@ basis={{ data: data_s, }} + {ls} + {locale} /> </div> </CarouselItem> diff --git a/apps-lib/src/lib/view/farms-products-view.svelte b/apps-lib/src/lib/view/farms-products-view.svelte @@ -4,23 +4,25 @@ LayoutPage, LayoutView, PageToolbar, - lls, } from "$root"; import { type CallbackPromise, type CallbackRoute, + type I18nTranslateFunction, type IViewBasis, type ResolveFarmProductInfo, } from "@radroots/util"; let { basis, + ls, }: { basis: IViewBasis<{ data: ResolveFarmProductInfo[]; callback_route?: CallbackRoute<string>; lc_handle_farm_product_add: CallbackPromise; }>; + ls: I18nTranslateFunction; } = $props(); </script> @@ -28,7 +30,7 @@ <PageToolbar basis={{ header: { - label: `${$lls(`common.products`)}`, + label: `${$ls(`common.products`)}`, callback_route: basis.callback_route || { route: `/farms` }, }, }} diff --git a/apps-lib/src/lib/view/farms-view.svelte b/apps-lib/src/lib/view/farms-view.svelte @@ -6,8 +6,6 @@ handle_err, LayoutPage, LayoutView, - liblocale, - lls, Map, MapMarkerArea, PageToolbar, @@ -21,6 +19,8 @@ type CallbackPromiseGeneric, type CallbackRoute, type GeolocationPointTuple, + type I18nTranslateFunction, + type I18nTranslateLocale, type IViewBasis, type LcGeocodeCallback, type ResolveFarmInfo, @@ -29,6 +29,8 @@ let { basis, + ls, + locale, }: { basis: IViewBasis<{ data: ResolveFarmInfo; @@ -38,6 +40,8 @@ lc_handle_farm_products_view: CallbackPromiseGeneric<string>; lc_handle_farm_orders_view: CallbackPromiseGeneric<string>; }>; + ls: I18nTranslateFunction; + locale: I18nTranslateLocale; } = $props(); let map: maplibregl.Map | undefined = $state(undefined); @@ -68,7 +72,7 @@ ? geol_lat_fmt( basis.data.geolocation.point.coordinates[1], `dms`, - $liblocale, + $locale, 3, ) : ``, @@ -79,7 +83,7 @@ ? geol_lng_fmt( basis.data.geolocation.point.coordinates[0], `dms`, - $liblocale, + $locale, 3, ) : ``, @@ -90,7 +94,7 @@ <PageToolbar basis={{ header: { - label: `${$lls(`common.farms`)} / ${basis.data.name || ``}`, + label: `${$ls(`common.farms`)} / ${basis.data.name || ``}`, callback_route: basis.callback_route, }, }} diff --git a/apps-lib/src/lib/view/farms.svelte b/apps-lib/src/lib/view/farms.svelte @@ -1,20 +1,21 @@ <script lang="ts"> - import ButtonLabelDashed from "$lib/components/button/button-label-dashed.svelte"; import { + ButtonLabelDashed, Fade, FarmsDisplayLiEl, GlyphButtonSimple, handle_err, - kv_init_page, + idb_init_page, LayoutPage, LayoutView, - lls, PageToolbar, } from "$root"; import { type CallbackPromise, type CallbackPromiseGeneric, type CallbackRoute, + type I18nTranslateFunction, + type I18nTranslateLocale, type IViewBasis, type LcGeocodeCallback, type ResolveFarmInfo, @@ -23,6 +24,8 @@ let { basis, + ls, + locale, }: { basis: IViewBasis<{ data?: ResolveFarmInfo[]; @@ -31,11 +34,13 @@ lc_handle_farm_add: CallbackPromise; lc_handle_farm_view: CallbackPromiseGeneric<string>; }>; + ls: I18nTranslateFunction; + locale: I18nTranslateLocale; } = $props(); onMount(async () => { try { - if (!basis.kv_init_prevent) await kv_init_page(); + if (!basis.kv_init_prevent) await idb_init_page(); } catch (e) { handle_err(e, `on_mount`); } @@ -46,7 +51,7 @@ <PageToolbar basis={{ header: { - label: `${$lls(`common.farms`)}`, + label: `${$ls(`common.farms`)}`, callback_route: basis.callback_route, }, }} @@ -56,7 +61,7 @@ <Fade> <GlyphButtonSimple basis={{ - label: `${$lls(`icu.add_*`, { value: `${$lls(`common.farm`)}` })}`, + label: `${$ls(`icu.add_*`, { value: `${$ls(`common.farm`)}` })}`, callback: async () => { await basis.lc_handle_farm_add(); }, @@ -73,6 +78,8 @@ basis={li} lc_geocode={basis.lc_geocode} lc_handle_farm_view={basis.lc_handle_farm_view} + {ls} + {locale} /> {/each} {:else} diff --git a/apps-lib/src/lib/view/home.svelte b/apps-lib/src/lib/view/home.svelte @@ -2,21 +2,22 @@ import { ButtonSimple, handle_err, - kv_init_page, + idb_init_page, LayoutPage, LayoutView, - lls, NavigationTabs, PageToolbar, } from "$root"; import { type CallbackPromise, + type I18nTranslateFunction, type IViewBasis, type ResolveAccountInfo, } from "@radroots/util"; import { onMount } from "svelte"; let { + ls, basis, }: { basis: IViewBasis<{ @@ -24,11 +25,12 @@ lc_handle_farms: CallbackPromise; lc_handle_products: CallbackPromise; }>; + ls: I18nTranslateFunction; } = $props(); onMount(async () => { try { - if (!basis.kv_init_prevent) await kv_init_page(); + if (!basis.kv_init_prevent) await idb_init_page(); } catch (e) { handle_err(e, `on_mount`); } @@ -39,14 +41,14 @@ <PageToolbar basis={{ header: { - label: `${$lls(`common.general`)}`, + label: `${$ls(`common.general`)}`, }, }} /> <LayoutPage> <ButtonSimple basis={{ - label: `${$lls(`common.farms`)}`, + label: `${$ls(`common.farms`)}`, callback: async () => { await basis.lc_handle_farms(); }, @@ -55,7 +57,7 @@ {#if basis.data?.farms?.length} <ButtonSimple basis={{ - label: `${$lls(`common.products`)}`, + label: `${$ls(`common.products`)}`, callback: async () => { await basis.lc_handle_products(); }, diff --git a/apps-lib/src/lib/view/notifications.svelte b/apps-lib/src/lib/view/notifications.svelte @@ -1,14 +1,17 @@ <script lang="ts"> - import { LayoutView, lls, NavigationTabs, PageToolbar } from "$root"; + import { LayoutView, NavigationTabs, PageToolbar } from "$root"; + import type { I18nTranslateFunction } from "@radroots/util"; let notifications: any[] = []; + + let { basis, ls }: { basis: {}; ls: I18nTranslateFunction } = $props(); </script> <LayoutView> <PageToolbar basis={{ header: { - label: `${$lls(`common.notifications`)} (${notifications.length})`, + label: `${$ls(`common.notifications`)} (${notifications.length})`, }, }} /> @@ -22,7 +25,7 @@ {:else} <div class={`flex flex-row w-full justify-center items-center`}> <p class={`font-sans font-[500] text-layer-0-glyph capitalize`}> - {`${$lls(`icu.no_*`, { value: `${$lls(`common.notifications`)}` })}`} + {`${$ls(`icu.no_*`, { value: `${$ls(`common.notifications`)}` })}`} </p> </div> {/if} diff --git a/apps-lib/src/lib/view/profile.svelte b/apps-lib/src/lib/view/profile.svelte @@ -1,12 +1,11 @@ <script lang="ts"> - import { lls } from "$lib/locale/i18n"; import { FloatPageButton, Glyph, handle_err, + idb_init_page, ImagePath, ImageUploadAddPhoto, - kv_init_page, } from "$root"; import { ascii, @@ -14,6 +13,7 @@ type CallbackPromiseFull, type CallbackPromiseGeneric, type CallbackPromiseReturn, + type I18nTranslateFunction, type IViewBasis, type LcPhotoAddCallback, type ResolveProfileInfo, @@ -22,6 +22,7 @@ let { basis, + ls, photo_path_opt = $bindable(``), loading_photo_upload = $bindable(false), }: { @@ -36,6 +37,7 @@ lc_handle_edit_profile_display_name: CallbackPromise; lc_handle_edit_profile_about: CallbackPromise; }>; + ls: I18nTranslateFunction; photo_path_opt: string; loading_photo_upload: boolean; } = $props(); @@ -45,7 +47,7 @@ onMount(async () => { try { - if (!basis.kv_init_prevent) await kv_init_page(); + if (!basis.kv_init_prevent) await idb_init_page(); if (basis.lc_on_mount) await basis.lc_on_mount(); } catch (e) { handle_err(e, `on_mount`); @@ -106,6 +108,7 @@ <div class={`flex flex-row justify-start items-center -translate-y-8`}> <ImageUploadAddPhoto bind:photo_path={photo_path_opt} + {ls} basis={{ lc_handle_photo_add: basis.lc_handle_photo_add, }} @@ -128,7 +131,7 @@ > {basis.data?.name ? basis.data.name - : `+ ${`${$lls(`icu.add_*`, { value: `${$lls(`common.profile_name`)}` })}`}`} + : `+ ${`${$ls(`icu.add_*`, { value: `${$ls(`common.profile_name`)}` })}`}`} </p> </button> </div> @@ -151,7 +154,7 @@ > {basis.data?.name ? `@${basis.data.name}` - : `+ ${`${$lls(`icu.add_*`, { value: `${$lls(`common.username`)}` })}`}`} + : `+ ${`${$ls(`icu.add_*`, { value: `${$ls(`common.username`)}` })}`}`} </p> </button> <p @@ -185,7 +188,7 @@ > {basis.data?.about ? `@${basis.data.about}` - : `+ ${`${$lls(`icu.add_*`, { value: `${$lls(`common.bio`)}` })}`}`} + : `+ ${`${$ls(`icu.add_*`, { value: `${$ls(`common.bio`)}` })}`}`} </p> </button> </div> diff --git a/apps-lib/src/lib/view/search.svelte b/apps-lib/src/lib/view/search.svelte @@ -3,11 +3,10 @@ fmt_id, Glyph, handle_err, + idb_init_page, Input, - kv_init_page, LayoutPage, LayoutView, - lls, NavigationTabs, PageToolbar, SearchResultDisplay, @@ -18,6 +17,7 @@ SearchService, type CallbackPromise, type CallbackPromiseGeneric, + type I18nTranslateFunction, type IViewBasis, type IViewSearchData, type ResolveGeolocationInfo, @@ -28,6 +28,7 @@ let { basis, + ls, }: { basis: IViewBasis<{ data: IViewSearchData; @@ -38,6 +39,7 @@ id: string; }>; }>; + ls: I18nTranslateFunction; } = $props(); $effect(() => { @@ -51,7 +53,7 @@ onMount(async () => { try { search_val = ``; - if (!basis.kv_init_prevent) await kv_init_page(); + if (!basis.kv_init_prevent) await idb_init_page(); if (basis.lc_on_mount) await basis.lc_on_mount(); search_service = new SearchService(basis.data); } catch (e) { @@ -76,7 +78,7 @@ <LayoutView> <PageToolbar basis={{ - header: { label: `${$lls(`common.search`)}` }, + header: { label: `${$ls(`common.search`)}` }, callback: basis.lc_handle_back, }} /> @@ -115,6 +117,7 @@ lc_handle_search_nostr_relay: basis.lc_handle_search_nostr_relay, }} + {ls} /> {/each} </div> diff --git a/apps-lib/src/lib/view/settings.svelte b/apps-lib/src/lib/view/settings.svelte @@ -2,10 +2,9 @@ import { app_thc, handle_err, - kv_init_page, + idb_init_page, LayoutTrellis, LayoutView, - lls, PageToolbar, Trellis, } from "$root"; @@ -13,6 +12,7 @@ ascii, type CallbackPromise, type CallbackPromiseGeneric, + type I18nTranslateFunction, type ISelectOption, type IViewBasis, } from "@radroots/util"; @@ -20,17 +20,19 @@ let { basis, + ls, }: { basis: IViewBasis<{ lc_color_mode: CallbackPromiseGeneric<ISelectOption<string>>; lc_settings_nostr: CallbackPromise; lc_logout: CallbackPromise; }>; + ls: I18nTranslateFunction; } = $props(); onMount(async () => { try { - if (!basis.kv_init_prevent) await kv_init_page(); + if (!basis.kv_init_prevent) await idb_init_page(); } catch (e) { handle_err(e, `on_mount`); } @@ -41,12 +43,13 @@ <PageToolbar basis={{ header: { - label: `${$lls(`common.settings`)}`, + label: `${$ls(`common.settings`)}`, }, }} /> <LayoutTrellis> <Trellis + {ls} basis={{ layer: 1, title: { @@ -59,7 +62,7 @@ label: { left: [ { - value: `${$lls(`common.color_mode`)}`, + value: `${$ls(`common.color_mode`)}`, classes: `capitalize`, }, ], @@ -77,16 +80,16 @@ entries: [ { value: ascii.bullet, - label: `${$lls(`icu.choose_*`, { value: `${$lls(`common.color_mode`)}`.toLowerCase() })}`, + label: `${$ls(`icu.choose_*`, { value: `${$ls(`common.color_mode`)}`.toLowerCase() })}`, disabled: true, }, { value: `light`, - label: `${$lls(`common.light`)}`, + label: `${$ls(`common.light`)}`, }, { value: `dark`, - label: `${$lls(`common.dark`)}`, + label: `${$ls(`common.dark`)}`, }, ], }, @@ -104,6 +107,7 @@ }} /> <Trellis + {ls} basis={{ layer: 1, list: [ @@ -113,7 +117,7 @@ label: { left: [ { - value: `${$lls(`common.logout`)}`, + value: `${$ls(`common.logout`)}`, classes: `capitalize`, }, ],