-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
171 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
{ | ||
"home": { | ||
"greeting": "Hi! I am {{name}}", | ||
"text": "<em>Internationalization (i18n) library to translate texts, dates and numbers in Qwik apps</em>" | ||
"text": "<em>Internationalization (i18n) library to translate texts, dates and numbers in Qwik apps</em>", | ||
"params": "Parameters", | ||
"tags": "Html tags", | ||
"plural": "Plural", | ||
"dates": "Dates", | ||
"numbers": "Numbers & currencies", | ||
"devs": { | ||
"one": "One software developer", | ||
"other": "{{value}} software developers" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
{ | ||
"home": { | ||
"greeting": "Ciao! Sono {{name}}", | ||
"text": "<em>Libreria di internazionalizzazione (i18n) per tradurre testi, date e numeri nelle app Qwik</em>" | ||
"text": "<em>Libreria di internazionalizzazione (i18n) per tradurre testi, date e numeri nelle app Qwik</em>", | ||
"params": "Parametri", | ||
"tags": "Tag Html", | ||
"plural": "Plurale", | ||
"dates": "Date", | ||
"numbers": "Numeri e valute", | ||
"devs": { | ||
"one": "Uno sviluppatore software", | ||
"other": "{{ value }} sviluppatori software" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
html { | ||
line-height: 1.5; | ||
-webkit-text-size-adjust: 100%; | ||
-moz-tab-size: 4; | ||
-o-tab-size: 4; | ||
tab-size: 4; | ||
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, | ||
'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', | ||
'Segoe UI Symbol', 'Noto Color Emoji'; | ||
} | ||
|
||
body { | ||
margin: 0; | ||
padding: 0; | ||
line-height: inherit; | ||
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', | ||
sans-serif; | ||
} | ||
|
||
main { | ||
padding: 10px 20px; | ||
max-width: 800px; | ||
margin: 0 auto; | ||
} | ||
|
||
.full-screen main { | ||
max-width: 100%; | ||
} | ||
|
||
a { | ||
color: #006eb3; | ||
} | ||
|
||
a:hover { | ||
text-decoration: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { translate } from './translate'; | ||
import type { SpeakState } from './types'; | ||
import { useSpeakContext } from './use-functions'; | ||
import { toNumber } from './utils'; | ||
|
||
/** | ||
* Get the plural by a number. | ||
* The value is passed as a parameter to the translate function | ||
* @param value A number or a string | ||
* @param prefix Optional prefix for the key | ||
* @param options Intl PluralRulesOptions object | ||
* @param ctx Optional Speak context to be provided outside the component$ | ||
* @param lang Optional language if different from the current one | ||
* @returns The translation for the plural | ||
*/ | ||
export const plural = ( | ||
value: number | string, | ||
prefix?: string, | ||
options?: Intl.PluralRulesOptions, | ||
ctx?: SpeakState, | ||
lang?: string | ||
): string | any => { | ||
ctx = ctx ?? useSpeakContext(); | ||
const { locale, config } = ctx; | ||
|
||
lang = lang ?? locale.lang; | ||
|
||
value = toNumber(value); | ||
|
||
const rule = new Intl.PluralRules(lang, options).select(value); | ||
const key = prefix ? `${prefix}${config.keySeparator}${rule}` : rule; | ||
|
||
return translate(key, { value }, ctx, lang); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { plural as p } from '../library/plural'; | ||
import { ctx } from './config'; | ||
|
||
describe('plural function', () => { | ||
test('one', () => { | ||
const value = p(1, '', {}, ctx); | ||
expect(value).toBe('One software developer'); | ||
}); | ||
test('other', () => { | ||
const value = p(2, '', {}, ctx); | ||
expect(value).toBe('2 software developers'); | ||
}); | ||
}); |