-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
expose Locales helper for legacy code in i18n
- Loading branch information
1 parent
6f4bd3b
commit cc6a006
Showing
9 changed files
with
253 additions
and
86 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
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,40 @@ | ||
/** | ||
* In the future we might want to standardize those exports | ||
* @see https://github.com/VulcanJS/vulcan-next/issues/9 | ||
*/ | ||
import { getLocale, getStrings } from "./locales"; | ||
|
||
//addGraphQLSchema(localeType); | ||
|
||
const locale = async (root, { localeId }, context) => { | ||
const locale = getLocale(localeId); | ||
const strings = getStrings(localeId); | ||
const localeObject = { ...locale, strings }; | ||
return localeObject; | ||
}; | ||
|
||
const typeDefs = `type Locale { | ||
id: String, | ||
label: String | ||
dynamic: Boolean | ||
strings: JSON | ||
} | ||
type Query { | ||
locale(localeId: String): Locale | ||
} | ||
`; | ||
const resolvers = { | ||
Query: { locale }, | ||
}; | ||
|
||
//addGraphQLQuery("locale(localeId: String): Locale"); | ||
//addGraphQLResolvers({ Query: { locale } }); | ||
|
||
/** | ||
* To be merged in your own schema | ||
*/ | ||
export const graphql = { | ||
typeDefs, | ||
resolvers, | ||
}; |
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 @@ | ||
export * from "./graphql"; |
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,44 @@ | ||
/** | ||
* Previously was defined in "intl" | ||
* | ||
* However we try to avoid this registry pattern as much as possible in Vulcan Next | ||
*/ | ||
|
||
export interface LocaleType { | ||
id: string; | ||
} | ||
|
||
export const Locales: Array<LocaleType> = []; | ||
|
||
/** | ||
* @deprecated Instead we should expose a Locale graphql model | ||
* @param locale | ||
*/ | ||
export const registerLocale = (locale: LocaleType) => { | ||
Locales.push(locale); | ||
}; | ||
|
||
/** | ||
* @deprecated | ||
*/ | ||
export const getLocale = (localeId: string) => { | ||
return Locales.find((locale) => locale.id === localeId); | ||
}; | ||
|
||
export const Strings: { [key: string]: any } = {}; | ||
|
||
export const Domains = {}; | ||
|
||
export const addStrings = (localeId, strings) => { | ||
if (typeof Strings[localeId] === "undefined") { | ||
Strings[localeId] = {}; | ||
} | ||
Strings[localeId] = { | ||
...Strings[localeId], | ||
...strings, | ||
}; | ||
}; | ||
|
||
export const getStrings = (localeId) => { | ||
return Strings[localeId]; | ||
}; |
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,10 @@ | ||
const merge = require("webpack-merge"); | ||
const path = require("path"); | ||
const baseConfig = require("../../webpack/webpack.config.base.server.prod"); | ||
//const merge = require('webpack-merge') | ||
module.exports = merge(baseConfig, { | ||
entry: path.resolve(__dirname, "./server/index.ts"), | ||
output: { | ||
path: path.resolve(__dirname, "dist/server"), | ||
}, | ||
}); |
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
Oops, something went wrong.