Skip to content

Commit

Permalink
Fix: add noSerialize to functions to avoid Code(3) error (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
robisim74 committed Aug 24, 2023
1 parent dd03a3f commit 15d47bf
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/translate.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Translate
> The return functions of `useTranslate`, `inlineTranslate` and `usePlural` are parsed and replaced with translated texts at compile time. For this reason, they expect _values_ or _identifiers_ as parameters, and no JavaScript _operators_
## useTranslate
`useTranslate` returns a functions to get the translation using key-value pairs:
Expand Down
3 changes: 2 additions & 1 deletion packages/qwik-speak/src/use-display-name.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { noSerialize } from '@builder.io/qwik';
import { useSpeakLocale } from './use-speak';

export type DisplayNameFn = {
Expand All @@ -20,5 +21,5 @@ export const useDisplayName = () => {
return new Intl.DisplayNames(lang, options).of(code) || code;
};

return displayName as DisplayNameFn;
return noSerialize(displayName) as DisplayNameFn;
};
4 changes: 2 additions & 2 deletions packages/qwik-speak/src/use-format-date.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

import { noSerialize } from '@builder.io/qwik';
import { useSpeakLocale } from './use-speak';

export type FormatDateFn = {
Expand Down Expand Up @@ -33,5 +33,5 @@ export const useFormatDate = (): FormatDateFn => {
return new Intl.DateTimeFormat(lang, options).format(value);
};

return formateDate as FormatDateFn;
return noSerialize(formateDate) as FormatDateFn;
};
3 changes: 2 additions & 1 deletion packages/qwik-speak/src/use-format-number.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { noSerialize } from '@builder.io/qwik';
import { useSpeakLocale } from './use-speak';

export type FormatNumberFn = {
Expand Down Expand Up @@ -32,5 +33,5 @@ export const useFormatNumber = () => {
return new Intl.NumberFormat(lang, options).format(value);
};

return formatNumber as FormatNumberFn;
return noSerialize(formatNumber) as FormatNumberFn;
};
3 changes: 2 additions & 1 deletion packages/qwik-speak/src/use-plural.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { noSerialize } from '@builder.io/qwik';
import { useSpeakContext } from './use-speak';
import { getValue } from './core';

Expand Down Expand Up @@ -42,5 +43,5 @@ export const usePlural = (): PluralFn => {
return getValue(key, translation[lang], { value, ...params }, config.keySeparator, config.keyValueSeparator);
};

return plural as PluralFn;
return noSerialize(plural) as PluralFn;
};
3 changes: 2 additions & 1 deletion packages/qwik-speak/src/use-relative-time.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { noSerialize } from '@builder.io/qwik';
import { useSpeakLocale } from './use-speak';

export type RelativeTimeFn = {
Expand Down Expand Up @@ -32,5 +33,5 @@ export const useRelativeTime = () => {
return new Intl.RelativeTimeFormat(lang, options).format(value, unit);
};

return relativeTime as RelativeTimeFn;
return noSerialize(relativeTime) as RelativeTimeFn;
};
3 changes: 2 additions & 1 deletion packages/qwik-speak/src/use-translate.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { noSerialize } from '@builder.io/qwik';
import { useSpeakContext } from './use-speak';
import { getValue } from './core';

Expand Down Expand Up @@ -39,5 +40,5 @@ export const useTranslate = (): TranslateFn => {
return getValue(keys, translation[lang], params, config.keySeparator, config.keyValueSeparator);
};

return translate as TranslateFn;
return noSerialize(translate) as TranslateFn;
};
2 changes: 1 addition & 1 deletion src/components/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const Header = component$(() => {
<>
<header class="header">
<div class="logo">
<Link href={getHref('/')}>
<Link href={getHref('/')} title={t('app.title')}>
<SpeakLogo />
</Link>
</div>
Expand Down

0 comments on commit 15d47bf

Please sign in to comment.