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

Fix language preferentiality for duplicate resources #12152

Merged
merged 3 commits into from
May 13, 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
21 changes: 21 additions & 0 deletions kolibri/core/assets/src/utils/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@ export const getContentLangDir = language => {
return (language || {}).lang_direction || languageDirections.LTR;
};

const contentLanguageCodes = {
ff: ['ful', 'fuv'],
ny: ['nya'],
sw: ['swa'],
yo: ['yor'],
};

export const getContentLangActive = language => {
const langCode = languageIdToCode(currentLanguage);
Copy link

Choose a reason for hiding this comment

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

The variable currentLanguage is used but not defined in the scope of getContentLangActive. Ensure that currentLanguage is correctly defined or passed as a parameter to this function.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's defined in the module scope.

const additionalCodes = contentLanguageCodes[langCode] || [];
if (language.id.toLowerCase() === currentLanguage.toLowerCase()) {
// Best possible match, return a 2 to have it still be truthy, but distinguishable
// from a 1 which is a lang_code match
return 2;
}
if (language.lang_code === langCode || additionalCodes.includes(language.lang_code)) {
return 1;
}
return 0;
};

const logging = logger.getLogger(__filename);

const languageGlobals = plugin_data['languageGlobals'] || {};
Expand Down
8 changes: 4 additions & 4 deletions kolibri/core/assets/src/utils/intl-locale-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This is an auto-generated file, any manual edits will be overridden.
*
* To regenerate, see instructions here:
* https://kolibri-dev.readthedocs.io/en/develop/references/i18n.html
* https://kolibri-dev.readthedocs.io/en/develop/i18n.html
*
* This file was generated by kolibri-tools i18n-code-gen
*
Expand Down Expand Up @@ -142,10 +142,10 @@ module.exports = function(locale) {
resolve(() => require('intl/locale-data/jsonp/my.js'));
});
});
case 'nyn':
case 'ny':
return new Promise(function(resolve) {
require.ensure(['intl/locale-data/jsonp/nyn.js'], function(require) {
resolve(() => require('intl/locale-data/jsonp/nyn.js'));
require.ensure(['kolibri-tools/lib/i18n/locale-data/intl/ny.js'], function(require) {
resolve(() => require('kolibri-tools/lib/i18n/locale-data/intl/ny.js'));
});
});
case 'pt-br':
Expand Down
4 changes: 2 additions & 2 deletions kolibri/core/assets/src/utils/vue-intl-locale-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This is an auto-generated file, any manual edits will be overridden.
*
* To regenerate, see instructions here:
* https://kolibri-dev.readthedocs.io/en/develop/references/i18n.html
* https://kolibri-dev.readthedocs.io/en/develop/i18n.html
*
* This file was generated by kolibri-tools i18n-code-gen
*
Expand Down Expand Up @@ -32,7 +32,7 @@ module.exports = function() {
data.push(require('vue-intl/locale-data/ko.js'));
data.push(require('vue-intl/locale-data/mr.js'));
data.push(require('vue-intl/locale-data/my.js'));
data.push(require('vue-intl/locale-data/nyn.js'));
data.push(require('vue-intl/locale-data/ny.js'));
data.push(require('vue-intl/locale-data/pt.js'));
data.push(require('vue-intl/locale-data/pt.js'));
data.push(require('vue-intl/locale-data/sw.js'));
Expand Down
177 changes: 177 additions & 0 deletions kolibri/core/auth/migrations/0026_update_language_code_nyn_to_ny.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2024-05-10 21:02
from __future__ import unicode_literals

from django.db import migrations

import kolibri.core.auth.constants.demographics
import kolibri.core.fields
import kolibri.core.utils.validators


class Migration(migrations.Migration):

dependencies = [
("kolibriauth", "0025_custom_demographic_schema"),
]

operations = [
migrations.AlterField(
model_name="facilitydataset",
name="extra_fields",
field=kolibri.core.fields.JSONField(
blank=True,
default={"facility": {}, "on_my_own_setup": False, "pin_code": ""},
null=True,
validators=[
kolibri.core.utils.validators.JSON_Schema_Validator(
{
"properties": {
"demographic_fields": {
"items": {
"properties": {
"description": {"type": "string"},
"enumValues": {
"items": {
"properties": {
"defaultLabel": {
"type": "string"
},
"translations": {
"items": {
"properties": {
"language": {
"enum": [
"ar",
"bg-bg",
"bn-bd",
"de",
"el",
"en",
"es-419",
"es-es",
"fa",
"ff-cm",
"fr-fr",
"gu-in",
"ha",
"hi-in",
"ht",
"id",
"it",
"ka",
"km",
"ko",
"mr",
"my",
"ny",
"pt-br",
"pt-mz",
"sw-tz",
"te",
"uk",
"ur-pk",
"vi",
"yo",
"zh-hans",
],
"type": "string",
},
"message": {
"type": "string"
},
},
"type": "object",
},
"optional": True,
"type": "array",
},
"value": {"type": "string"},
},
"type": "object",
},
"type": "array",
},
"id": {"type": "string"},
"translations": {
"items": {
"properties": {
"language": {
"enum": [
"ar",
"bg-bg",
"bn-bd",
"de",
"el",
"en",
"es-419",
"es-es",
"fa",
"ff-cm",
"fr-fr",
"gu-in",
"ha",
"hi-in",
"ht",
"id",
"it",
"ka",
"km",
"ko",
"mr",
"my",
"ny",
"pt-br",
"pt-mz",
"sw-tz",
"te",
"uk",
"ur-pk",
"vi",
"yo",
"zh-hans",
],
"type": "string",
},
"message": {"type": "string"},
},
"type": "object",
},
"optional": True,
"type": "array",
},
},
"type": "object",
},
"optional": True,
"type": "array",
},
"facility": {"optional": True, "type": "object"},
"on_my_own_setup": {
"optional": True,
"type": "boolean",
},
"pin_code": {
"optional": True,
"type": ["string", "null"],
},
},
"type": "object",
}
),
kolibri.core.auth.constants.demographics.UniqueIdsValidator(
"demographic_fields"
),
kolibri.core.auth.constants.demographics.DescriptionTranslationValidator(
"demographic_fields"
),
kolibri.core.auth.constants.demographics.EnumValuesValidator(
"demographic_fields"
),
kolibri.core.auth.constants.demographics.LabelTranslationValidator(
"demographic_fields"
),
],
),
),
]
Loading
Loading