From b6e3ac8bc6e1596265090a65b8d6926d34a8907a Mon Sep 17 00:00:00 2001 From: Baris Aydek Date: Thu, 26 Jun 2025 03:11:42 +0300 Subject: [PATCH 1/4] created text.json and using t helper function for user facing texts, ability to inject through wnjParams --- src/App.svelte | 133 ++++++++++++++++++++++++++++--------------------- src/main.ts | 4 +- src/texts.json | 40 +++++++++++++++ 3 files changed, 119 insertions(+), 58 deletions(-) create mode 100644 src/texts.json diff --git a/src/App.svelte b/src/App.svelte index bb40e99..617f577 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -42,6 +42,17 @@ position export let startHidden: boolean export let compactMode: boolean + export let texts: Record + + // Helper function to get text with fallback + function t(key: string): string { + const value = texts[key] + if (value) return value + + console.warn(`Text not found: ${key}`) + + return key + } const win = window as any const pool = new SimplePool() @@ -83,10 +94,12 @@ let metadataSub: SubCloser | null let pendingRejections: ((reason?: any) => void)[] = [] - const connectBunkerError = + $: connectBunkerError = t( 'We could not connect to a NIP-46 bunker with that url, are you sure it is set up correctly?' - const connectNip05Error = + ) + $: connectNip05Error = t( 'We were not able to connect using this address. For it to work it has to come from a NIP-46 provider.' + ) const BASE_YPOS = 20 export let right = 20 @@ -563,14 +576,14 @@ {#if connecting}
- Connecting to bunker + {t('Connecting to bunker')}
{:else if !identity} {#if compactMode}
N
{:else} -
Connect with Nostr
+
{t('Connect with Nostr')}
{/if} {:else if !compactMode}
@@ -616,51 +629,55 @@ {#if showAuth}
-
Create a Nostr account
+
{t('Create a Nostr account')}
- A new window will now open, taking you to + {t('A new window will now open, taking you to')} {new URL(showAuth).host} - where the account creation will occur. If nothing happens, ensure your - browser is not blocking popups. -
Afterward, you'll be redirected back to this page. + {t( + 'where the account creation will occur. If nothing happens, ensure your browser is not blocking popups.' + )} +
+ {t("Afterward, you'll be redirected back to this page.")}
{:else if showLogin}
-
Login into a Nostr account
+
+ {t('Login into a Nostr account')} +
- A new window will now open, taking you to {new URL(showLogin).host} - where you can login and approve the permissions. If nothing happens, - ensure your browser is not blocking popups.
- Afterward, you'll be redirected back to this page. + {t('A new window will now open, taking you to')} + {new URL(showLogin).host} + {t( + 'where you can login and approve the permissions. If nothing happens, ensure your browser is not blocking popups.' + )}
+ {t("Afterward, you'll be redirected back to this page.")}
{:else if showConfirmAction}
- An action requires your confirmation + {t('An action requires your confirmation')}
- A new window will now open, taking you to {new URL(showConfirmAction).host} - where you can approve the current action. If nothing happens, ensure - your browser is not blocking popups.
- Afterward, you'll be redirected back to this page. + {t('A new window will now open, taking you to')} + {new URL(showConfirmAction).host} + {t( + 'where you can approve the current action. If nothing happens, ensure your browser is not blocking popups.' + )}
+ {t("Afterward, you'll be redirected back to this page.")}
{:else if showInfo} -
What is that?
+
{t('What is that?')}

- This widget is created with window.nostr.js, a small script - you can drop in any page that already uses NIP-07 and make it also - work with NIP-46 automatically when the user doesn't have an - extension installed. + {t( + "This widget is created with window.nostr.js, a small script you can drop in any page that already uses NIP-07 and make it also work with NIP-46 automatically when the user doesn't have an extension installed." + )}
- It adds a small floating button on the side of the window that users - can use to create Nostr accuonts or connect to their NIP-46 bunkers. + {t( + 'It adds a small floating button on the side of the window that users can use to create Nostr accuonts or connect to their NIP-46 bunkers.' + )}

- This tool is opensource, get the code from the project's page{t("project's page")}.

- You don't know what Nostr is? + {t("You don't know what Nostr is?")} Learn more{t('Learn more')}.

{:else if creating} -
Create a Nostr account
+
{t('Create a Nostr account')}
- To use this Nostr app you need a profile. The following button opens a - wizard that help you to create your keypair and safely manage it in a - few steps. Are you ready? + {t( + 'To use this Nostr app you need a profile. The following button opens a wizard that help you to create your keypair and safely manage it in a few steps. Are you ready?' + )}
- Do you already have a Nostr address?
+ {t('Do you already have a Nostr address?')}
{t('Login now')}
{:else if !identity}
- How do you want to connect to Nostr? + {t('How do you want to connect to Nostr?')}
{#if connecting} - Connecting to bunker + {t('Connecting to bunker')} {:else} - Connect » + {t('Connect »')} {/if} {#if connecting && takingTooLong}
- Waiting too much? + {t('Waiting too much?')} {t('Cancel the connection')}
{/if} @@ -770,16 +789,16 @@ {#if !connecting}
{#if hasTriedToConnectButFailed} - Is this bunker provider broken?
+ {t('Is this bunker provider broken?')}
{t('Clear it')} {:else} - Do you need a Nostr account?
+ {t('Do you need a Nostr account?')}
{t('Sign up now')} {/if}
@@ -788,7 +807,7 @@ {:else}
-
You are connected to Nostr as
+
{t('You are connected to Nostr as')}
{t('Disconnect')}
- This webpage is using the public key:
+ {t('This webpage is using the public key:')}
{getPublicKey(clientSecret)}
{/if} diff --git a/src/main.ts b/src/main.ts index 5304b84..e911583 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,6 @@ import styles from './app.css?inline' import App from './App.svelte' +import defaultTexts from './texts.json' // To customize the widget add this code before the diff --git a/src/main.ts b/src/main.ts index e911583..bfe9d3d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -40,7 +40,8 @@ const app = new App({ position: win.wnjParams?.position === 'bottom' ? 'bottom' : 'top', startHidden: win.wnjParams?.startHidden, compactMode: win.wnjParams?.compactMode, - texts: win.wnjParams?.texts || defaultTexts + texts: win.wnjParams?.texts || defaultTexts, + nstartMeLanguage: win.wnjParams?.nstartMeLanguage || 'en' } })