Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration examples adjustments #169

Merged
merged 2 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ i18n.runWithLocale(locale, func)

## Integrations

This section showcases some of the ways of integrating `universe:i18n` with different frameworks. More detailed examples can be found in the `integrations` directory.
This section showcases some of the ways of integrating `universe:i18n` with different frameworks. More detailed examples can be found in the [`integrations` directory](https://github.com/vazco/meteor-universe-i18n/blob/master/integrations).

### Integration with React

Expand Down
2 changes: 1 addition & 1 deletion integrations/blaze/App.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ <h1>Example of i18n</h1>

<template name="i18nTemplate">
<span>{{__ 'ok'}}</span>
<span>{{{__ 'test'}}}</span>
<span>{{{__ 'dog'}}}</span>
</template>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
_locale: en
ok: Okay
test: <b>Test</b>
dog: Dog
3 changes: 3 additions & 0 deletions integrations/blaze/locales/es.i18n.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_locale: es
ok: Bien
dog: Perro
3 changes: 2 additions & 1 deletion integrations/blaze/reactivei18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { i18n } from 'meteor/universe:i18n';
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';

import './en.i18n.yml';
import './locales/en.i18n.yml';
import './es/en.i18n.yml';
import './main.html';

const localeReactive = new ReactiveVar<string>(i18n.getLocale());
Expand Down
1 change: 0 additions & 1 deletion integrations/react/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const Example = () => {
Are you sure?
<button>{t('ok')}</button>
<button>{t('dog')}</button>
<input placeholder={t('company.placeholder')} />
</>
);
};
Expand Down
6 changes: 0 additions & 6 deletions integrations/react/en.i18n.yml

This file was deleted.

3 changes: 3 additions & 0 deletions integrations/react/locales/en.i18n.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_locale: en
ok: Okay
dog: Dog
3 changes: 3 additions & 0 deletions integrations/react/locales/es.i18n.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_locale: es
ok: Bien
dog: Perro
3 changes: 2 additions & 1 deletion integrations/react/reactivei18n.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import React, {
useContext,
} from 'react';

import './en.i18n.yml';
import './locales/en.i18n.yml';
import './locales/es.i18n.yml';

const localeContext = createContext(i18n.getLocale());

Expand Down
9 changes: 4 additions & 5 deletions integrations/svelte/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,20 @@
<div>
Locale: {$locale}
<br />
hi: {$t('hi')}
<br />
ok: {$t('ok')}
<br />
apple: {$t('apple')}
dog: {$t('dog')}
</div>
<br />

<!-- Example of updating locale in the DB from client level-->
Locale to update:
<input placeholder="e.g. es" bind:value={localeToUpdate} /><br />
<input placeholder="e.g. en" bind:value={localeToUpdate} /><br />
Key to update:
<input placeholder="e.g. apple" bind:value={keyToUpdate} /><br />
<input placeholder="e.g. dog" bind:value={keyToUpdate} /><br />
New value:
<input placeholder="e.g. Green apple" bind:value={valueToUpdate} /><br />
<input placeholder="e.g. Big dog" bind:value={valueToUpdate} /><br />
<button
on:click={() => {
const newTranslation = {};
Expand Down
2 changes: 0 additions & 2 deletions integrations/svelte/locales/en.i18n.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
_locale: en
hi: Hello
ok: Okay
apple: Apple
dog: Dog
2 changes: 0 additions & 2 deletions integrations/svelte/locales/es.i18n.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
_locale: es
hi: Hola
ok: Bien
apple: Manzana
dog: Perro
2 changes: 2 additions & 0 deletions integrations/svelte/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ function refresh(locale, { translations = {}, updatedAt = new Date() }) {
}

const mergeTranslations = (baseTranslations, translation) => {
// This is just a basic example of shallow merge
// To assure correct merge of objects deep merge should be used
return Object.assign({}, translation, baseTranslations);
};

Expand Down