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

Update langnames #662

Merged
merged 3 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gateway-edit",
"version": "2.4.0",
"version": "2.4.1",
"engines": {
"node": ">=18.18.0"
},
Expand Down
99 changes: 99 additions & 0 deletions src/common/__tests__/languages.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/* eslint-env jest */
import * as Languages from '../languages';

describe('Test Languages',()=>{
const minimumLangCount = 9000;

test('getLanguage() should work with mixed and lower case', () => {
const codes = ['sr-latn', 'sr-Latn', 'SR-LATN', 'ur-deva', 'ur-Deva', 'UR-DEVA', 'ZH'];

for (let languageId of codes) {
const languageData = Languages.getLanguage({languageId});
expect(languageData).toBeTruthy();
expect(languageData.languageId.toLowerCase()).toEqual(languageId.toLowerCase());
}
});

test('getLanguages() should work', () => {
const languages = Languages.getLanguages();
const langCount = languages.length;
expect(langCount).toBeLessThan(minimumLangCount * 1.2);

// make sure fields are valid and in sequence
for (let i = 1; i < langCount; i++) {
const lang = languages[i - 1];
expect(lang.languageId.length).toBeGreaterThan(0);
const languageName = lang.languageName || lang.localized
if (!languageName.length) {
console.log(`invalid languageName ${languageName} for languageId ${lang.languageId}`)
}
expect(lang.localized.length).toBeGreaterThan(0);
if (!lang.localized.length) {
console.log(`invalid localized ${lang.localized} for languageId ${lang.languageId}`)
}
expect(lang.localized.length).toBeGreaterThan(0);
const directionValid = lang.direction === 'ltr' || lang.direction === 'rtl'
if (!lang.localized.length) {
console.log(`invalid direction ${lang.direction} for languageId ${lang.languageId}`)
}
expect(directionValid).toBeTruthy();
}
});

test('getLanguages() verify no dupes among language codes.', () => {
let languages = Languages.getLanguages();
let localLanguageCodes = languages.map(language => language.languageId);

const sorted = localLanguageCodes.sort();
let dupsFound = 0;

for ( let idx = 1; idx < sorted.length; idx++ ) {
if ( sorted[idx] == sorted[idx-1]) {
dupsFound++;
}
}

expect(dupsFound).toBeLessThan(1);
expect(sorted.length).toBeGreaterThan(minimumLangCount);
});

test('getGatewayLanguages() verify no dupes among language codes.', async () => {
let languages = await Languages.getGatewayLanguages();
let localLanguageCodes = languages.map(language => language.languageId);

const sorted = localLanguageCodes.sort();
let dupsFound = 0;

for ( let idx = 1; idx < sorted.length; idx++ ) {
if ( sorted[idx] == sorted[idx-1]) {
dupsFound++;
}
}

expect(dupsFound).toBeLessThan(1);
const minimumGwLangs = 40;
const maximumGwLangs = 100;
expect(sorted.length).toBeGreaterThan(minimumGwLangs);
expect(sorted.length).not.toBeGreaterThan(maximumGwLangs);
});

describe('getLanguage()',()=>{
test('Nepali ne should succeed', () => {
const code = 'ne';
const name = 'Nepali';
let foundLanguage = Languages.getLanguage({ languageId: code });

expect(foundLanguage.languageName).toEqual(name);
expect(foundLanguage.languageId).toEqual(code);
});

test('Nepali npi should succeed', () => {
const code = 'npi';
const name = 'Nepali';
let foundLanguage = Languages.getLanguage({ languageId: code });

expect(foundLanguage.languageName).toEqual(name);
expect(foundLanguage.languageId).toEqual(code);
});
});
});
5 changes: 4 additions & 1 deletion src/common/languages.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import languagesJSON from './languages.json'

export const getLanguage = ({ languageId }) => {
let _language
const language = languagesJSON.filter(object => object.lc === languageId)[0]
languageId = languageId.toLowerCase()
const language = languagesJSON.find(object => {
return object.lc?.toLowerCase() === languageId // compare lower case
})
_language = formatLanguage({ language })
return _language
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/languages.json

Large diffs are not rendered by default.

Loading