-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Show language name with -s option to resolve an indeterminate la…
…nguage for auto detection
- Loading branch information
Showing
7 changed files
with
48 additions
and
8 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
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,11 @@ | ||
import { iso6391X } from '@kabeep/node-translate'; | ||
|
||
function getLanguageName(from?: string, detectFrom?: string) { | ||
const code = !from || from === 'auto' ? detectFrom : from; | ||
|
||
const language = code ? iso6391X.getName(code) : ''; | ||
|
||
return language || detectFrom; | ||
} | ||
|
||
export default getLanguageName; |
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,5 +1,6 @@ | ||
export { default as catcher } from './catcher.js'; | ||
export { default as getColumns } from './get-columns.js'; | ||
export { default as getLanguageName } from './get-language-name.js'; | ||
export { default as isError } from './is-error.js'; | ||
export { Info, Success, Warning, Failure } from './notify.js'; | ||
export { Translation, Source, Synonym, Polysemy, Sentence, Language, Adaptive, Code } from './typography.js'; |
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,27 @@ | ||
import { expect, test } from 'vitest'; | ||
import getLanguageName from '../../src/utils/get-language-name'; | ||
|
||
test('getLanguageName - should return undefined when both from and detectFrom are undefined', () => { | ||
const result = getLanguageName(); | ||
expect(result).toBe(undefined); | ||
}); | ||
|
||
test('getLanguageName - should return the language name when from is provided', () => { | ||
const result = getLanguageName('en', 'English'); | ||
expect(result).toBe('English'); | ||
}); | ||
|
||
test('getLanguageName - should return the detected language name when from is not provided', () => { | ||
const result = getLanguageName(undefined, 'en'); | ||
expect(result).toBe('English'); | ||
}); | ||
|
||
test('getLanguageName - should return the detected language name when from is "auto"', () => { | ||
const result = getLanguageName('auto', 'en'); | ||
expect(result).toBe('English'); | ||
}); | ||
|
||
test('getLanguageName - should return the detected language name when from is not valid', () => { | ||
const result = getLanguageName('auto', 'Unknown'); | ||
expect(result).toBe('Unknown'); | ||
}); |