Skip to content

Commit

Permalink
fix: language auto-matching, refresh due to form submission (#257) (#258
Browse files Browse the repository at this point in the history
)

Co-authored-by: BBK <[email protected]>
  • Loading branch information
kalvkusk and BBK912 authored Feb 29, 2024
1 parent 92a7a85 commit e2cc990
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@
})
</script>
{#if $isLoading}

Please wait...
<main class="uk-background-muted uk-height-viewport uk-flex uk-flex-center uk-flex-middle uk-flex-column" >
<span class="uk-text-large">Please wait...</span>
</main>
{:else}
<main class="uk-background-muted uk-height-viewport" >
<Style />
Expand Down
2 changes: 1 addition & 1 deletion src/components/wallet/AccountFromMnemForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{$_('wallet.account_from_mnem_from.title')}
</h3>
<p>{$_('wallet.account_from_mnem_from.description')}</p>
<form id="account-form">
<form id="account-form" on:submit|preventDefault={() => {}}>
<fieldset class="uk-fieldset">
<div class="uk-margin uk-inline-block uk-width-1-1">
<input
Expand Down
2 changes: 1 addition & 1 deletion src/components/wallet/AccountFromPrivateKey.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<main>
<div class="uk-margin">
<p>{$_('wallet.account_from_private.description')}</p>
<form id="account-form">
<form id="account-form" on:submit|preventDefault={() => {}}>
<fieldset class="uk-fieldset">
<div class="uk-margin uk-inline-block uk-width-1-1">
<input
Expand Down
16 changes: 14 additions & 2 deletions src/lang/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,19 @@ function setupI18n(options) {
fallbackLocale: 'en',
})
}

const fixedLocales = {
zh: 'zh_cn',
}
function getLocale() {
// The value of locale is taken from the browser navigator.language, and the first part is taken here to adapt it to the language key defined by carpe.
// where zh-CN requires special handling
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/language
let locale = getLocaleFromNavigator()
if (locale) {
locale = locale.toLocaleLowerCase().split('-')[0]
}
return fixedLocales[locale] || locale
}
// We expose the svelte-i18n _ store so that our app has
// a single API for i18n
export { _, setupI18n, getLocaleFromNavigator, locale }
export { _, setupI18n, getLocale, locale }
5 changes: 3 additions & 2 deletions src/modules/preferences.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { invoke } from '@tauri-apps/api/tauri'
import { get, writable } from 'svelte/store'
import { getLocaleFromNavigator, setupI18n } from '../lang/i18n'
import { getLocale, setupI18n } from '../lang/i18n'
import { Level, logger, raise_error } from './carpeError'
import { signingAccount } from './accounts'
import { notify_success } from './carpeNotify'
Expand Down Expand Up @@ -31,7 +31,8 @@ export const init_locale_preferences = () => {
})

const acct = get(signingAccount)
const locale = acct && acct.locale ? acct.locale : getLocaleFromNavigator()

const locale = acct && acct.locale ? acct.locale : getLocale()
setupI18n({
withLocale: locale,
fallbackLocale: 'en',
Expand Down

0 comments on commit e2cc990

Please sign in to comment.