-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ♻️ flytt messages til egen fil i utils * ♻️ importer messages fra utils * 💩 hello pello Co-authored-by: Halvor Grizzly Bjørn <[email protected]> Co-authored-by: Tor Idland <[email protected]> * 🐛 fjerner test-poop commit som ikke skulle vært her --------- Co-authored-by: Tor Idland <[email protected]> Co-authored-by: Halvor Grizzly Bjørn <[email protected]>
- Loading branch information
1 parent
dbd5840
commit 2899f69
Showing
3 changed files
with
42 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export const SUPPORTED_LOCALE = ['nb', 'nn']; | ||
import { DecoratorLocale } from '@navikt/nav-dekoratoren-moduler'; | ||
|
||
export const SUPPORTED_LOCALE: DecoratorLocale[] = ['nb', 'nn']; |
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,30 @@ | ||
import messagesNb from 'lib/translations/nb.json'; | ||
import messagesNn from 'lib/translations/nn.json'; | ||
import { DecoratorLocale } from '@navikt/nav-dekoratoren-moduler'; | ||
|
||
type GenericMessageObject = { | ||
[key: string]: any; | ||
}; | ||
function flattenMessages(nestedMessages: GenericMessageObject, prefix = ''): Record<string, string> { | ||
return Object.keys(nestedMessages).reduce<GenericMessageObject>((messages, key) => { | ||
let value = nestedMessages[key]; | ||
let prefixedKey = prefix ? `${prefix}.${key}` : key; | ||
|
||
if (typeof value === 'string') { | ||
messages[prefixedKey] = value; | ||
} else { | ||
Object.assign(messages, flattenMessages(value, prefixedKey)); | ||
} | ||
|
||
return messages; | ||
}, {}); | ||
} | ||
|
||
type Messages = { | ||
[K in DecoratorLocale]?: { [name: string]: string }; | ||
}; | ||
|
||
export const messages: Messages = { | ||
nb: flattenMessages(messagesNb), | ||
nn: flattenMessages(messagesNn), | ||
}; |
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