Skip to content

Commit

Permalink
Merge pull request #12152 from rtibbles/language!
Browse files Browse the repository at this point in the history
Fix language preferentiality for duplicate resources
  • Loading branch information
marcellamaki committed May 13, 2024
2 parents ec43861 + 00d7f70 commit 32e1e94
Show file tree
Hide file tree
Showing 39 changed files with 640 additions and 26 deletions.
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);
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"
),
],
),
),
]

0 comments on commit 32e1e94

Please sign in to comment.