Skip to content

Commit

Permalink
Renamed enableDebug to showLogs
Browse files Browse the repository at this point in the history
  • Loading branch information
3adel-bassiony committed Jan 27, 2024
1 parent cd68ec4 commit d787a9c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ The I18XS package comes with a comprehensive set of features designed to make in
// ... more key-value pairs
},
localesDir: './path/to/locales/folder',
enableDebug: true,
showLogs: true,
})
```
Expand All @@ -190,7 +190,7 @@ The I18XS package comes with a comprehensive set of features designed to make in
// ... more key-value pairs
},
localesDir: './path/to/locales/folder',
enableDebug: true,
showLogs: true,
})
```
Expand Down
30 changes: 15 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default class I18XS {
/**
* Indicates whether debug mode is enabled.
*/
protected _enableDebug: boolean = false
protected _showLogs: boolean = false

/**
* Creates an instance of the I18XS class.
Expand All @@ -72,7 +72,7 @@ export default class I18XS {
* farewell: 'Au revoir'
* }
* },
* enableDebug: true
* showLogs: true
* });
*/
constructor({
Expand All @@ -84,7 +84,7 @@ export default class I18XS {
rtlLocales = ['ar', 'he', 'fa', 'ur', 'ps', 'ckb', 'syr', 'dv', 'ug'],
localesDir = null,
localization = null,
enableDebug = false,
showLogs = false,
}: I18XSConfig) {
this._supportedLocales = supportedLocales
this._currentLocale = currentLocale
Expand All @@ -93,7 +93,7 @@ export default class I18XS {
this._missingIdentifierMessage = missingIdentifierMessage
this._rtlLocales = rtlLocales
this._localesDir = localesDir
this._enableDebug = enableDebug
this._showLogs = showLogs

if (localization) {
this._localization = localization
Expand Down Expand Up @@ -196,7 +196,7 @@ export default class I18XS {
* }
*/
get isDebugEnabled(): boolean {
return this._enableDebug
return this._showLogs
}

/**
Expand Down Expand Up @@ -224,7 +224,7 @@ export default class I18XS {
* farewell: 'Au revoir'
* }
* },
* enableDebug: true
* showLogs: true
* });
*/
configure({
Expand All @@ -236,7 +236,7 @@ export default class I18XS {
rtlLocales = ['ar', 'he', 'fa', 'ur', 'ps', 'ckb', 'syr', 'dv', 'ug'],
localesDir = null,
localization = null,
enableDebug = false,
showLogs = false,
}: I18XSConfig): I18XS {
this._supportedLocales = supportedLocales
this._currentLocale = currentLocale
Expand All @@ -245,7 +245,7 @@ export default class I18XS {
this._missingIdentifierMessage = missingIdentifierMessage
this._rtlLocales = rtlLocales
this._localesDir = localesDir
this._enableDebug = enableDebug
this._showLogs = showLogs

if (localization) {
this._localization = localization
Expand All @@ -270,7 +270,7 @@ export default class I18XS {
*/
changeCurrentLocale(locale: string): I18XS {
if (!this._supportedLocales.includes(locale)) {
if (this._enableDebug) {
if (this._showLogs) {
console.error(
`Locale ${locale} is not supported, please add it to the supported locales or change the current locale to a supported one`
)
Expand All @@ -281,7 +281,7 @@ export default class I18XS {

this._currentLocale = locale

if (this._enableDebug) {
if (this._showLogs) {
console.debug(`Changed current locale to ${locale}`)
}

Expand Down Expand Up @@ -323,11 +323,11 @@ export default class I18XS {
fileContents = fs.readFileSync(filePath, 'utf8')
this._localization = JSON.parse(fileContents)

if (this._enableDebug) {
if (this._showLogs) {
console.debug({ 'Loaded localization': this._localization })
}
} else if (fs.existsSync(fallbackFilePath)) {
if (this._enableDebug) {
if (this._showLogs) {
console.debug(
`Localization file not found for ${this._currentLocale}, using ${this._fallbackLocale} instead`
)
Expand All @@ -337,18 +337,18 @@ export default class I18XS {
this._currentLocale = this._fallbackLocale
this._localization = JSON.parse(fileContents)

if (this._enableDebug) {
if (this._showLogs) {
console.debug({ 'Loaded localization for fallback locale': this._localization })
}
} else {
if (this._enableDebug) {
if (this._showLogs) {
console.debug(
`Localization file not found for both ${this._currentLocale} and ${this._fallbackLocale}`
)
}
}
} catch (error) {
if (this._enableDebug) {
if (this._showLogs) {
console.error({ 'Failed to load localization': error })
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/tests/i18n.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('I18XS', () => {
currentLocale: 'ar',
supportedLocales: ['ar', 'fr'],
localization: { Hello_World: 'مرحبا بالعالم' },
enableDebug: true,
showLogs: true,
})
expect(i18xs.currentLocale).toBe('ar')
expect(i18xs.supportedLocales).toEqual(['ar', 'fr'])
Expand Down Expand Up @@ -271,7 +271,7 @@ describe('I18XS', () => {
})

// test('It should enable debug mode', async () => {
// const i18xs = new I18XS({ currentLocale: 'he', supportedLocales: ['en', 'ar'], enableDebug: true })
// const i18xs = new I18XS({ currentLocale: 'he', supportedLocales: ['en', 'ar'], showLogs: true })
// expect(i18xs.isDebugEnabled).toBe(true)
// i18xs.changeCurrentLocale('ar')
// const consoleSpy = vi.spyOn(console, 'debug')
Expand Down
2 changes: 1 addition & 1 deletion src/types/I18XSConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export type I18XSConfig = {
rtlLocales?: string[]
localization?: Localization | null
localesDir?: string | null
enableDebug?: boolean
showLogs?: boolean
}

0 comments on commit d787a9c

Please sign in to comment.