|
11 | 11 |
|
12 | 12 | log = logging.getLogger(__name__) |
13 | 13 |
|
| 14 | +# https://github.com/openedx/openedx-platform/issues/38036 |
| 15 | +NORMALIZE_LANGUAGE_CODES = { |
| 16 | + "zh-hans": "zh-cn", |
| 17 | + "zh-hant": "zh-hk", |
| 18 | + "ca@valencia": "ca-es-valencia", |
| 19 | +} |
| 20 | + |
14 | 21 |
|
15 | 22 | def backfill_openedx_catalog(apps, schema_editor): |
16 | 23 | """ |
@@ -59,12 +66,19 @@ def backfill_openedx_catalog(apps, schema_editor): |
59 | 66 | display_name: str = (course_overview.display_name if course_overview else None) or course_code |
60 | 67 |
|
61 | 68 | # Determine the course language. |
| 69 | + # Note that in Studio, the options for course language generally came from the ALL_LANGUAGES setting, which is |
| 70 | + # mostly two-letter language codes with no locale, except it uses "zh_HANS" for Mandarin and "zh_HANT" for |
| 71 | + # Cantonese. We normalize those to "zh-cn" and "zh-hk" for consistency with our platform UI languages / |
| 72 | + # Transifex, but you can still access the "old" version using the CatalogCourse.language_short |
| 73 | + # getter/setter for backwards compatbility. See https://github.com/openedx/openedx-platform/issues/38036 |
62 | 74 | language = settings.LANGUAGE_CODE |
63 | 75 | if course_overview and course_overview.language: |
64 | 76 | language = course_overview.language.lower() |
65 | | - if len(language) > 2 and language[2] == "_": |
66 | | - language[2] = "-" # Ensure we use hyphens for consistency (`en-us` not `en_us`) |
67 | | - if len(language) > 2 and language[2] not in ("-", "@"): |
| 77 | + language = language.replace("_", "-") # Ensure we use hyphens for consistency (`en-us` not `en_us`) |
| 78 | + # Normalize this language code. The previous/non-normalized code will still be available via the |
| 79 | + # "language_short" property for backwards compatibility. |
| 80 | + language = NORMALIZE_LANGUAGE_CODES.get(language, language) |
| 81 | + if len(language) > 2 and language[2] != "-": |
68 | 82 | # This seems like an invalid value; revert to the default: |
69 | 83 | log.warning( |
70 | 84 | 'The course with ID "%s" has invalid language "%s" - using default language "%s" instead.', |
@@ -102,7 +116,7 @@ def backfill_openedx_catalog(apps, schema_editor): |
102 | 116 | raise ValueError( |
103 | 117 | f"The course {course_run.course_id} exists in modulestore with a different capitalization of its " |
104 | 118 | f'course code compared to other instances of the same run ("{course_code}" vs "{cc.course_code}"). ' |
105 | | - 'This really should not happen. To fix it, delete the inconsistent course runs (!). ' |
| 119 | + "This really should not happen. To fix it, delete the inconsistent course runs (!). " |
106 | 120 | ) |
107 | 121 |
|
108 | 122 | # Create the CourseRun |
|
0 commit comments