From 19143be58337f29acfb036b916a5ac359e528f2a Mon Sep 17 00:00:00 2001 From: Bruno Inec Date: Tue, 2 Jan 2024 00:44:45 +0100 Subject: [PATCH 1/6] Push Docker image to registry after release --- .github/workflows/deploying.yml | 49 +++++++++++++++++++++++++++++++++ dockerfile | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploying.yml b/.github/workflows/deploying.yml index 92cdfbe8..9c642cf6 100644 --- a/.github/workflows/deploying.yml +++ b/.github/workflows/deploying.yml @@ -127,3 +127,52 @@ jobs: asset_path: ./movie-web.zip asset_name: movie-web.zip asset_content_type: application/zip + + registry: + name: Push to registry + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + id-token: write + + env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v2 + + - name: Get version + id: package-version + uses: martinbeentjes/npm-get-version-action@main + + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: | + latest=auto + tags: | + type=semver,pattern={{version}},value=v${{ steps.package-version.outputs.current-version }} + + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@v4 + with: + push: true + context: . + labels: ${{ steps.meta.outputs.labels }} + tags: ${{ steps.meta.outputs.tags }} diff --git a/dockerfile b/dockerfile index 52b585fa..5dd5465b 100644 --- a/dockerfile +++ b/dockerfile @@ -13,6 +13,6 @@ RUN pnpm run build # production environment FROM nginx:stable-alpine -COPY --from=build /app/build /usr/share/nginx/html +COPY --from=build /app/dist /usr/share/nginx/html EXPOSE 80 CMD ["nginx", "-g", "daemon off;"] From eec1e28e8e7e35f8d3b692608f84b5cfa18624e7 Mon Sep 17 00:00:00 2001 From: William Oldham Date: Sat, 6 Jan 2024 10:42:48 +0000 Subject: [PATCH 2/6] Update language util to get region from the locale code where available --- src/utils/language.ts | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/utils/language.ts b/src/utils/language.ts index 5f05113c..4d31bc1d 100644 --- a/src/utils/language.ts +++ b/src/utils/language.ts @@ -5,19 +5,11 @@ const languageOrder = ["en", "hi", "fr", "de", "nl", "pt"]; // mapping of language code to country code. // multiple mappings can exist, since languages are spoken in multiple countries. -// This mapping purely exists to prioritize a country over another in languages. +// This mapping purely exists to prioritize a country over another in languages where the +// base language code does not contain a region (i.e. if the language code is zh-Hant where Hant is a script) // iso639_1 -> iso3166 Alpha-2 const countryPriority: Record = { - en: "us", - nl: "nl", - fr: "fr", - de: "de", - pt: "pt", - ar: "sa", - es: "es", zh: "cn", - ko: "kr", - ta: "lk", }; // list of iso639_1 Alpha-2 codes used as default languages @@ -89,7 +81,7 @@ function populateLanguageCode(language: string): string { } /** - * @param locale idk what kinda code this takes, anytihhng in ietf format I guess + * @param locale idk what kinda code this takes, anything in ietf format I guess * @returns pretty format for language, null if it no info can be found for language */ export function getPrettyLanguageNameFromLocale(locale: string): string | null { @@ -105,12 +97,12 @@ export function getPrettyLanguageNameFromLocale(locale: string): string | null { } /** - * Sort locale codes by occurance, rest on alphabetical order + * Sort locale codes by occurrence, rest on alphabetical order * @param langCodes list language codes to sort * @returns sorted version of inputted list */ export function sortLangCodes(langCodes: string[]) { - const languagesOrder = [...languageOrder].reverse(); // Reverse is neccesary, not sure why + const languagesOrder = [...languageOrder].reverse(); // Reverse is necessary, not sure why const results = langCodes.sort((a, b) => { const langOrderA = languagesOrder.findIndex( @@ -137,20 +129,34 @@ export function getCountryCodeForLocale(locale: string): string | null { const tag = getTag(locale, true); if (!tag?.language?.Subtag) return null; - // this function isnt async, so its garuanteed to work like this + // this function isn't async, so its guaranteed to work like this countryLanguages.getLanguage(tag.language.Subtag, (_err, lang) => { if (lang) output = lang; }); + if (!output) return null; const priority = countryPriority[output.iso639_1.toLowerCase()]; if (output.countries.length === 0) { return priority ?? null; } + + // If the language contains a region, check that against the countries and + // return the region if it matches + const regionSubtag = tag?.region?.Subtag.toLowerCase(); + if (regionSubtag) { + const regionCode = output.countries.find( + (c) => + c.code_2.toLowerCase() === regionSubtag || + c.code_3.toLowerCase() === regionSubtag, + ); + if (regionCode) return regionCode.code_2.toLowerCase(); + } + if (priority) { - const priotizedCountry = output.countries.find( + const prioritizedCountry = output.countries.find( (v) => v.code_2.toLowerCase() === priority, ); - if (priotizedCountry) return priotizedCountry.code_2.toLowerCase(); + if (prioritizedCountry) return prioritizedCountry.code_2.toLowerCase(); } return output.countries[0].code_2.toLowerCase(); } From 8a7e277d1c543fa168c9f0d139e68226d2840ade Mon Sep 17 00:00:00 2001 From: William Oldham Date: Sat, 6 Jan 2024 10:44:21 +0000 Subject: [PATCH 3/6] Update language readme --- src/assets/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/assets/README.md b/src/assets/README.md index e8c04d52..d3820f45 100644 --- a/src/assets/README.md +++ b/src/assets/README.md @@ -3,7 +3,7 @@ Locales are difficult, here is some guidance. ## Process on adding new languages -1. Use weblate to add translations, see contributing guidelines. +1. Use Weblate to add translations, see contributing guidelines. 2. Add your language to `@/assets/languages.ts`. Must be in ISO format (ISO-639 for language and ISO-3166 for country/region). For joke languages, use any format. -3. If your language doesn't have a region specified (Such as in `pt-BR`, `BR` being the region). Add a default region in `@/utils/language.ts` at `defaultLanguageCodes` -4. If the flag in the language dropdown doesn't match the correct one. Add a default country in `@/utils/language.ts` at `countryPriority`. +3. If the language code doesn't have a region specified (Such as in `pt-BR`, `BR` being the region), add a default region in `@/utils/language.ts` at `defaultLanguageCodes` +4. If the language code doesn't contain a region (Such as in `zh-Hant`), add a default country in `@/utils/language.ts` at `countryPriority`. From d8c96f2b6d204ce9c6d5734fb800422419ae34aa Mon Sep 17 00:00:00 2001 From: William Oldham Date: Sat, 6 Jan 2024 10:46:16 +0000 Subject: [PATCH 4/6] Use priority ahead of region --- src/utils/language.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/utils/language.ts b/src/utils/language.ts index 4d31bc1d..94837660 100644 --- a/src/utils/language.ts +++ b/src/utils/language.ts @@ -5,8 +5,8 @@ const languageOrder = ["en", "hi", "fr", "de", "nl", "pt"]; // mapping of language code to country code. // multiple mappings can exist, since languages are spoken in multiple countries. -// This mapping purely exists to prioritize a country over another in languages where the -// base language code does not contain a region (i.e. if the language code is zh-Hant where Hant is a script) +// This mapping purely exists to prioritize a country over another in languages where the base language code does +// not contain a region (i.e. if the language code is zh-Hant where Hant is a script) or if the region in the language code is incorrect // iso639_1 -> iso3166 Alpha-2 const countryPriority: Record = { zh: "cn", @@ -140,6 +140,13 @@ export function getCountryCodeForLocale(locale: string): string | null { return priority ?? null; } + if (priority) { + const prioritizedCountry = output.countries.find( + (v) => v.code_2.toLowerCase() === priority, + ); + if (prioritizedCountry) return prioritizedCountry.code_2.toLowerCase(); + } + // If the language contains a region, check that against the countries and // return the region if it matches const regionSubtag = tag?.region?.Subtag.toLowerCase(); @@ -151,13 +158,6 @@ export function getCountryCodeForLocale(locale: string): string | null { ); if (regionCode) return regionCode.code_2.toLowerCase(); } - - if (priority) { - const prioritizedCountry = output.countries.find( - (v) => v.code_2.toLowerCase() === priority, - ); - if (prioritizedCountry) return prioritizedCountry.code_2.toLowerCase(); - } return output.countries[0].code_2.toLowerCase(); } From 86e81dcd05cfe6ae13b415383eccade3d502a9ef Mon Sep 17 00:00:00 2001 From: William Oldham Date: Sat, 6 Jan 2024 12:31:22 +0000 Subject: [PATCH 5/6] Use populate language code for country code method --- src/utils/language.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/language.ts b/src/utils/language.ts index 94837660..1b60dac3 100644 --- a/src/utils/language.ts +++ b/src/utils/language.ts @@ -126,7 +126,7 @@ export function sortLangCodes(langCodes: string[]) { */ export function getCountryCodeForLocale(locale: string): string | null { let output: LanguageObj | null = null as any as LanguageObj; - const tag = getTag(locale, true); + const tag = getTag(populateLanguageCode(locale), true); if (!tag?.language?.Subtag) return null; // this function isn't async, so its guaranteed to work like this From 4c3528892fe445833092993823f1ab90a0055508 Mon Sep 17 00:00:00 2001 From: William Oldham Date: Sat, 6 Jan 2024 12:36:59 +0000 Subject: [PATCH 6/6] Sort default language codes for neatness --- src/utils/language.ts | 44 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/utils/language.ts b/src/utils/language.ts index 1b60dac3..2364e6a6 100644 --- a/src/utils/language.ts +++ b/src/utils/language.ts @@ -14,37 +14,37 @@ const countryPriority: Record = { // list of iso639_1 Alpha-2 codes used as default languages const defaultLanguageCodes: string[] = [ - "en-US", + "ar-SA", + "bg-BG", + "bn-BD", "cs-CZ", "de-DE", + "el-GR", + "en-US", + "es-ES", + "et-EE", + "fa-IR", "fr-FR", - "pt-BR", + "gl-ES", + "gu-IN", + "he-IL", + "id-ID", "it-IT", + "ja-JP", + "ko-KR", + "lv-LV", + "ne-NP", "nl-NL", "pl-PL", + "pt-BR", + "ru-RU", + "sl-SI", + "sv-SE", + "ta-LK", + "th-TH", "tr-TR", "vi-VN", "zh-CN", - "he-IL", - "sv-SE", - "lv-LV", - "th-TH", - "ne-NP", - "ar-SA", - "es-ES", - "et-EE", - "bg-BG", - "bn-BD", - "el-GR", - "fa-IR", - "gu-IN", - "id-ID", - "ja-JP", - "ko-KR", - "sl-SI", - "ta-LK", - "ru-RU", - "gl-ES", ]; export interface LocaleInfo {