Skip to content

Commit

Permalink
feat(javascript): add i18n to wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
NateFerrero committed Jul 3, 2024
1 parent af477c2 commit 4d4493d
Show file tree
Hide file tree
Showing 36 changed files with 1,014 additions and 577 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-pears-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@flatfile/javascript': minor
---

Add internationalization support with detected browser language or given override language.
10 changes: 10 additions & 0 deletions apps/vanilla/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ export const config = {
labels: ['pinned'],
sheets: [
{
actions: [
{
operation: 'customAction',
mode: 'foreground',
label: 'Custom Action',
icon: 'none',
description: 'Do something custom',
primary: true,
},
],
name: 'Contacts',
slug: 'contacts',
allowAdditionalFields: true,
Expand Down
24 changes: 24 additions & 0 deletions apps/vanilla/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,30 @@
<button onclick="initializeFlatfile('pk_123456')">
Open "On Demand" Flatfile
</button>

<label>Override language:</label>
<select id="override-language">
<option selected value=""></option>
<option value="de">de</option>
<option value="en">en</option>
<option value="en-GB">en-GB</option>
<option value="en-CA">en-CA</option>
<option value="en-ZA">en-ZA</option>
<option value="es">es</option>
<option value="fr">fr</option>
<option value="fr-CA">fr-CA</option>
<option value="fr-FR">fr-FR</option>
<option value="id">id</option>
<option value="it">it</option>
<option value="jp">jp</option>
<option value="kr">kr</option>
<option value="pt">pt</option>
<option value="pt-BR">pt-BR</option>
<option value="tr">tr</option>
<option value="vi">vi</option>
<option value="zh">zh</option>
</select>

<script>
window.addEventListener('load', (event) => {
preloadFlatfile()
Expand Down
11 changes: 11 additions & 0 deletions apps/vanilla/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ import { createIframe, initializeFlatfile } from '@flatfile/javascript'

import { config } from './config'
import { listener } from './listener'

const overrideLanguageSelect = document.getElementById('override-language')
overrideLanguageSelect.addEventListener('change', () => {
localStorage.setItem('overrideLanguage', overrideLanguageSelect.value)
})
const overrideLanguage = localStorage.getItem('overrideLanguage')
if (overrideLanguage) {
overrideLanguageSelect.value = overrideLanguage
}

/*
// ---Get a space to reuse it, load automatically
const flatfile = new FlatfileClient({
Expand Down Expand Up @@ -33,6 +43,7 @@ getSpace()
*/

const BASE_OPTIONS = {
languageOverride: overrideLanguageSelect.value,
spaceBody: { name: 'Hello' },
// listener,
// Additional parameters...
Expand Down
48 changes: 40 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4d4493d

Please sign in to comment.