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

chore: remove Ditto words #1673

Merged
merged 1 commit into from
Aug 19, 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
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ dist
.github
globals.d.ts
generated
ditto
cypress/*
37 changes: 0 additions & 37 deletions .github/workflows/translation-update.yml

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ dist
.env
yarn-error.log
coverage
ditto/*__*.json
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules
ditto
dist
.github
generated
Expand Down
397 changes: 0 additions & 397 deletions ditto/config.yml

This file was deleted.

28 changes: 0 additions & 28 deletions ditto/index.d.ts

This file was deleted.

523 changes: 0 additions & 523 deletions ditto/index.js

This file was deleted.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
"start:build": "yarn build && npx http-server-spa ./dist",
"build": "webpack --config ./webpack.prod.js",
"build:analyseBundle": "webpack --config ./webpack.prod.js --env analyseBundle",
"ditto": "yarn ditto-cli pull && node scripts/MergeTranslationFiles.js",
"ditto:addNew": "yarn ditto-cli project add",
"lint": "prettier --check src/**/*.{ts,tsx,svg,html} --check cypress/**/*.ts && eslint \"**/*.{js,ts,tsx}\"",
"eslint": "eslint \"**/*.{js,ts,tsx}\"",
"lint:fix": "prettier --write {src,cypress}/** && eslint --fix .",
Expand All @@ -34,7 +32,6 @@
"@babel/plugin-syntax-dynamic-import": "7.8.3",
"@babel/preset-env": "7.22.20",
"@babel/preset-react": "7.22.15",
"@dittowords/cli": "4.4.1",
"@emotion/react": "11.11.1",
"@emotion/styled": "11.11.0",
"@graphql-codegen/cli": "4.0.1",
Expand Down
37 changes: 0 additions & 37 deletions scripts/MergeTranslationFiles.js

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/translations/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const fs = require('fs')

const { globSync } = require('glob')

const TRANSLATION_FILES_PATH = './ditto/base.json' // './ditto/**.json' for when we'll support several languages
const TRANSLATION_FILES_PATH = './translations/base.json' // './translations/**.json' for when we'll support several languages

const KEY_RANDOM_CHARS_LENGTH = 11

Expand Down
32 changes: 16 additions & 16 deletions scripts/translations/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { globSync } = require('glob')
const { GettextExtractor, JsExtractors } = require('gettext-extractor')

const SRC_DIR = './src/'
const TRANSLATION_FILES_PATH = './ditto/base.json' // './ditto/**.json' for when we'll support several languages
const TRANSLATION_FILES_PATH = './translations/base.json' // './translations/**.json' for when we'll support several languages

async function extract(replaceMode) {
// Extract all the translation keys by parsing the 'translate' function
Expand Down Expand Up @@ -42,38 +42,38 @@ async function extract(replaceMode) {
const translationFiles = globSync(TRANSLATION_FILES_PATH)

translationFiles.forEach((file) => {
// Get all translation keys from the ditto file
const dittoTranslations = JSON.parse(fs.readFileSync(file), 'utf-8')
// Get all translation keys from the translation file
const allTranslations = JSON.parse(fs.readFileSync(file), 'utf-8')
// Ignore timezone keys as they're used in the config without calling translate
const dittoKeys = Object.keys(dittoTranslations).filter((key) => key.split('_')[0] !== 'TZ')
const keysNotInDitto = _.uniq(_.difference(foundKeys, dittoKeys))
const dittoKeysNotUsed = _.uniq(_.difference(dittoKeys, foundKeys))
const translationKeys = Object.keys(allTranslations).filter((key) => key.split('_')[0] !== 'TZ')
const keysNotInTranslations = _.uniq(_.difference(foundKeys, translationKeys))
const translationKeysNotUsed = _.uniq(_.difference(translationKeys, foundKeys))

if (dittoKeysNotUsed.length || keysNotInDitto.length) {
if (keysNotInDitto.length) {
if (translationKeysNotUsed.length || keysNotInTranslations.length) {
if (keysNotInTranslations.length) {
console.info(
'\u001b[' +
31 +
'm' +
`\n----- Keys used but not defined ----- ${keysNotInDitto.length}` +
`\n----- Keys used but not defined ----- ${keysNotInTranslations.length}` +
'\u001b[0m',
)
console.info(keysNotInDitto.join('\n'))
console.info(keysNotInTranslations.join('\n'))
}
if (dittoKeysNotUsed.length) {
if (translationKeysNotUsed.length) {
console.info(
'\u001b[' +
31 +
'm' +
`\n----- Keys defined but not used ----- ${dittoKeysNotUsed.length}` +
`\n----- Keys defined but not used ----- ${translationKeysNotUsed.length}` +
'\u001b[0m',
)
console.info(dittoKeysNotUsed.join('\n'))
console.info(translationKeysNotUsed.join('\n'))

if (replaceMode) {
for (let i = 0; i < dittoKeysNotUsed.length; i++) {
const key = dittoKeysNotUsed[i]
const translation = dittoTranslations[key]
for (let i = 0; i < translationKeysNotUsed.length; i++) {
const key = translationKeysNotUsed[i]
const translation = allTranslations[key]

// Iterate through each file to replace the translation string
for (let j = 0; j < files.length; j++) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/translations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export type TranslateData = Record<string, string | number | undefined | null>

export type Translations = Record<string, string> | undefined

export interface DittoTranslation {
export interface Translation {
[key: string]: string
}

Expand Down
12 changes: 5 additions & 7 deletions src/core/translations/utils.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import { AppEnvEnum } from '~/core/constants/globalTypes'

import { DittoTranslation, Locale, TranslateData, Translations } from './types'
import { Locale, TranslateData, Translation, Translations } from './types'

export const getTranslations: (locale: Locale) => Promise<Record<string, string>> = async (
locale,
) => {
let loadedDittoTranslation: DittoTranslation
let loadedTranslation: Translation

// Translations are dinamically imported according to the selected locale
try {
loadedDittoTranslation = (await import(`../../../ditto/${locale}.json`)) as DittoTranslation
loadedTranslation = (await import(`../../../translations/${locale}.json`)) as Translation
} catch (err) {
loadedDittoTranslation = (await import(
`../../../ditto/base.json`
)) as unknown as DittoTranslation
loadedTranslation = (await import(`../../../translations/base.json`)) as unknown as Translation
}

return loadedDittoTranslation
return loadedTranslation
}

export function replaceDynamicVarInString(template: string, data: TranslateData) {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/core/useContextualLocale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { useCallback, useEffect, useState } from 'react'

import { envGlobalVar } from '~/core/apolloClient'
import {
DittoTranslation,
getTranslations,
Locale,
TranslateData,
translateKey,
Translation,
} from '~/core/translations'

const { appEnv } = envGlobalVar()
Expand All @@ -16,7 +16,7 @@ type UseContextualLocale = (locale: Locale) => {
}

export const useContextualLocale: UseContextualLocale = (locale) => {
const [translations, setTranslations] = useState<DittoTranslation>()
const [translations, setTranslations] = useState<Translation>()

useEffect(() => {
const updateTranslations = async () => {
Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions ditto/de.json → translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
"text_64188b3d9735d5007d712282": "LAG-1234-567-981",
"text_64188b3d9735d5007d712283": "Ausstellungsdatum",
"text_64188b3d9735d5007d712284": "02. Sep. 2023",
"__variant-name": "German",
"__variant-description": "",
"text_641d6ae1d947c400671e6abb": "Etwas ist schiefgelaufen",
"text_641d6aee014c8d00c1425cdd": "Bitte aktualisieren Sie die Seite oder kontaktieren Sie uns, wenn der Fehler weiterhin besteht.",
"text_641d6b00ef96c1008754734d": "Seite aktualisieren",
Expand Down
2 changes: 0 additions & 2 deletions ditto/es.json → translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
"text_64188b3d9735d5007d712282": "LAG-1234-567-981",
"text_64188b3d9735d5007d712283": "Fecha de emisión",
"text_64188b3d9735d5007d712284": "01 de sep. de 2023",
"__variant-name": "Spanish",
"__variant-description": "",
"text_641d6ae1d947c400671e6abb": "Algo salió mal",
"text_641d6aee014c8d00c1425cdd": "Actualice la página o póngase en contacto con nosotros si el error persiste.",
"text_641d6b00ef96c1008754734d": "Actualizar la página",
Expand Down
2 changes: 0 additions & 2 deletions ditto/fr.json → translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
"text_64188b3d9735d5007d712282": "LAG-1234-567-981",
"text_64188b3d9735d5007d712283": "Date d'émission",
"text_64188b3d9735d5007d712284": "1 Sep, 2023",
"__variant-name": "French",
"__variant-description": "",
"text_641d6ae1d947c400671e6abb": "Quelque chose n'a pas fonctionné",
"text_641d6aee014c8d00c1425cdd": "Veuillez actualiser la page ou nous contacter si l'erreur persiste.",
"text_641d6b00ef96c1008754734d": "Actualiser la page",
Expand Down
2 changes: 0 additions & 2 deletions ditto/it.json → translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
"text_64188b3d9735d5007d712282": "LAG-1234-567-981",
"text_64188b3d9735d5007d712283": "Data Emissione",
"text_64188b3d9735d5007d712284": "01 Set. 2023",
"__variant-name": "Italian",
"__variant-description": "",
"text_641d6ae1d947c400671e6abb": "Qualcosa è andato storto",
"text_641d6aee014c8d00c1425cdd": "Ti preghiamo di aggiornare la pagina o di contattarci se l'errore persiste.",
"text_641d6b00ef96c1008754734d": "Aggiorna la pagina",
Expand Down
2 changes: 0 additions & 2 deletions ditto/nb.json → translations/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
"text_64188b3d9735d5007d712282": "LAG-1234-567-981",
"text_64188b3d9735d5007d712283": "Dato",
"text_64188b3d9735d5007d712284": "2 Sep, 2023",
"__variant-name": "Norwegian",
"__variant-description": "",
"text_641d6ae1d947c400671e6abb": "Noe gikk galt",
"text_641d6aee014c8d00c1425cdd": "Oppdater siden eller kontakt oss hvis feilen vedvarer.",
"text_641d6b00ef96c1008754734d": "Oppdater siden",
Expand Down
2 changes: 0 additions & 2 deletions ditto/sv.json → translations/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
"text_64188b3d9735d5007d712282": "LAG-1234-567-981",
"text_64188b3d9735d5007d712283": "Fakturadatum",
"text_64188b3d9735d5007d712284": "1 sep. 2023",
"__variant-name": "Swedish",
"__variant-description": "",
"text_641d6ae1d947c400671e6abb": "Något gick fel",
"text_641d6aee014c8d00c1425cdd": "Uppdatera sidan eller kontakta oss om felet kvarstår.",
"text_641d6b00ef96c1008754734d": "Uppdatera sidan",
Expand Down
Loading
Loading