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

feat: Disable FS backend when user provides one #930

Merged
merged 5 commits into from
Feb 21, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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 src/config/createConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const createConfig = (userConfig: UserConfig): InternalConfig => {
if (!process.browser) {
combinedConfig.preload = locales

const hasCustomBackend = userConfig?.use?.find((b) => b.type === 'backend')
const hasCustomBackend = userConfig?.use?.some((b) => b.type === 'backend')

if (!hasCustomBackend) {
const fs = require('fs')
Expand Down
2 changes: 1 addition & 1 deletion src/createClient/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { InternalConfig, CreateClientReturn, InitPromise } from '../../types'

export default (config: InternalConfig): CreateClientReturn => {
const instance = i18n.createInstance(config)

let initPromise: InitPromise

if (!instance.isInitialized) {
instance.use(i18nextHTTPBackend)

config.use.forEach(x => instance.use(x))
initPromise = instance.init(config)
}
Expand Down
4 changes: 3 additions & 1 deletion src/createClient/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export default (config: InternalConfig): CreateClientReturn => {
let initPromise: InitPromise

if (!instance.isInitialized) {
instance.use(i18nextFSBackend)
const hasCustomBackend = config?.use?.some((b) => b.type === 'backend')
if (!hasCustomBackend)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use curly braces here, please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing!

instance.use(i18nextFSBackend)

config.use.forEach(x => instance.use(x))
initPromise = instance.init(config)
Expand Down
1 change: 1 addition & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type UserConfig = {
use?: any[]
} & InitOptions


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, removed

export type InternalConfig = Omit<UserConfig, 'i18n'> & NextJsI18NConfig & {
errorStackTraceLimit: number
fallbackLng: boolean
Expand Down