Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

feat(frontend:i18n): add support for language display names and enhance select options with localized text

johavenf9a68bff83c4
diff --git a/frontend/src/app/applications/admin/components/dialogs/admin-user-dialog.component.html b/frontend/src/app/applications/admin/components/dialogs/admin-user-dialog.component.html
index 89e6ee86..7d9abd5e 100644
--- a/frontend/src/app/applications/admin/components/dialogs/admin-user-dialog.component.html
+++ b/frontend/src/app/applications/admin/components/dialogs/admin-user-dialog.component.html
@@ -97,7 +97,7 @@
formControlName="language"
class="form-control form-select form-select-sm">
@for (l of languages; track $index) {
- <option [ngValue]="l">{{ l }}</option>
+ <option [ngValue]="l">{{ i18nLanguageText[l] }}</option>
}
</select>
</div>
diff --git a/frontend/src/app/applications/admin/components/dialogs/admin-user-dialog.component.ts b/frontend/src/app/applications/admin/components/dialogs/admin-user-dialog.component.ts
index a3a434c4..b3c5e9a3 100644
--- a/frontend/src/app/applications/admin/components/dialogs/admin-user-dialog.component.ts
+++ b/frontend/src/app/applications/admin/components/dialogs/admin-user-dialog.component.ts
@@ -29,6 +29,7 @@ import { BsModalRef } from 'ngx-bootstrap/modal'
import { TabDirective, TabHeadingDirective, TabsetComponent } from 'ngx-bootstrap/tabs'
import { Observable } from 'rxjs'
import { take } from 'rxjs/operators'
+import { i18nLanguageText } from '../../../../../i18n/l10n'
import { InputPasswordComponent } from '../../../../common/components/input-password.component'
import { PasswordStrengthBarComponent } from '../../../../common/components/password-strength-bar.component'
import { StorageQuotaComponent } from '../../../../common/components/storage-quota.component'
@@ -109,6 +110,7 @@ export class AdminUserDialogComponent implements OnInit {
groups: FormControl<MemberModel[]>
applications: FormControl<USER_PERMISSION[]>
}>
+ protected readonly i18nLanguageText = i18nLanguageText
private readonly adminService = inject(AdminService)
private readonly userService = inject(UserService)
@@ -238,7 +240,9 @@ export class AdminUserDialogComponent implements OnInit {
}
private makeDto(create: true): CreateUserDto
+
private makeDto(create?: false): UpdateUserDto
+
private makeDto(create = false): CreateUserDto | UpdateUserDto {
let dto = {}
if (create) {
diff --git a/frontend/src/app/applications/links/components/dialogs/link-dialog.component.html b/frontend/src/app/applications/links/components/dialogs/link-dialog.component.html
index 05b71494..77885594 100644
--- a/frontend/src/app/applications/links/components/dialogs/link-dialog.component.html
+++ b/frontend/src/app/applications/links/components/dialogs/link-dialog.component.html
@@ -142,7 +142,7 @@
formControlName="language"
class="form-control form-select form-select-sm ms-auto w-50">
@for (l of languages; track $index) {
- <option [ngValue]="l">{{ l }}</option>
+ <option [ngValue]="l">{{ i18nLanguageText[l] }}</option>
}
</select>
</div>
diff --git a/frontend/src/app/applications/links/components/dialogs/link-dialog.component.ts b/frontend/src/app/applications/links/components/dialogs/link-dialog.component.ts
index af77f690..d409581c 100644
--- a/frontend/src/app/applications/links/components/dialogs/link-dialog.component.ts
+++ b/frontend/src/app/applications/links/components/dialogs/link-dialog.component.ts
@@ -24,6 +24,7 @@ import { ButtonsModule } from 'ngx-bootstrap/buttons'
import { BsDatepickerModule } from 'ngx-bootstrap/datepicker'
import { TooltipModule } from 'ngx-bootstrap/tooltip'
import { Observable } from 'rxjs'
+import { i18nLanguageText } from '../../../../../i18n/l10n'
import { InputPasswordComponent } from '../../../../common/components/input-password.component'
import { PasswordStrengthBarComponent } from '../../../../common/components/password-strength-bar.component'
import { originalOrderKeyValue } from '../../../../common/utils/functions'
@@ -100,6 +101,7 @@ export class LinkDialogComponent implements OnInit {
permissions: FormControl<string | null>
isActive: FormControl<boolean>
}>
+ protected readonly i18nLanguageText = i18nLanguageText
private readonly userService = inject(UserService)
private readonly sharesService = inject(SharesService)
private readonly linksService = inject(LinksService)
diff --git a/frontend/src/app/applications/users/components/dialogs/user-guest-dialog.component.html b/frontend/src/app/applications/users/components/dialogs/user-guest-dialog.component.html
index fe9fbbff..e5821db1 100644
--- a/frontend/src/app/applications/users/components/dialogs/user-guest-dialog.component.html
+++ b/frontend/src/app/applications/users/components/dialogs/user-guest-dialog.component.html
@@ -97,7 +97,7 @@
formControlName="language"
class="form-control form-select form-select-sm">
@for (l of languages; track $index) {
- <option [ngValue]="l">{{ l }}</option>
+ <option [ngValue]="l">{{ i18nLanguageText[l] }}</option>
}
</select>
</div>
diff --git a/frontend/src/app/applications/users/components/dialogs/user-guest-dialog.component.ts b/frontend/src/app/applications/users/components/dialogs/user-guest-dialog.component.ts
index fee9e078..9ac263f0 100644
--- a/frontend/src/app/applications/users/components/dialogs/user-guest-dialog.component.ts
+++ b/frontend/src/app/applications/users/components/dialogs/user-guest-dialog.component.ts
@@ -16,6 +16,7 @@ import type { SearchMembersDto } from '@sync-in-server/backend/src/applications/
import { L10N_LOCALE, L10nLocale, L10nTranslateDirective, L10nTranslatePipe } from 'angular-l10n'
import { TabDirective, TabHeadingDirective, TabsetComponent } from 'ngx-bootstrap/tabs'
import { Observable } from 'rxjs'
+import { i18nLanguageText } from '../../../../../i18n/l10n'
import { InputPasswordComponent } from '../../../../common/components/input-password.component'
import { PasswordStrengthBarComponent } from '../../../../common/components/password-strength-bar.component'
import { AutofocusDirective } from '../../../../common/directives/auto-focus.directive'
@@ -79,6 +80,7 @@ export class UserGuestDialogComponent implements OnInit {
isActive: FormControl<boolean>
managers: FormControl<MemberModel[]>
}>
+ protected readonly i18nLanguageText = i18nLanguageText
ngOnInit() {
this.guestForm = new FormGroup({
@@ -171,7 +173,9 @@ export class UserGuestDialogComponent implements OnInit {
}
protected makeDto(create: true): CreateUserDto
+
protected makeDto(create?: false): UpdateUserDto
+
protected makeDto(create = false): CreateUserDto | UpdateUserDto {
let dto = {}
if (create) {
diff --git a/frontend/src/app/applications/users/components/user-account.component.html b/frontend/src/app/applications/users/components/user-account.component.html
index 1b48a01c..aa2b0996 100755
--- a/frontend/src/app/applications/users/components/user-account.component.html
+++ b/frontend/src/app/applications/users/components/user-account.component.html
@@ -107,7 +107,7 @@
<div class="col-auto">
<select [(ngModel)]="language" class="form-select form-select-sm">
@for (l of languages; track $index) {
- <option [ngValue]="l">{{ l }}</option>
+ <option [ngValue]="l">{{ i18nLanguageText[l] }}</option>
}
</select>
</div>
diff --git a/frontend/src/app/applications/users/components/user-account.component.ts b/frontend/src/app/applications/users/components/user-account.component.ts
index a82eb3c1..7b5eef37 100644
--- a/frontend/src/app/applications/users/components/user-account.component.ts
+++ b/frontend/src/app/applications/users/components/user-account.component.ts
@@ -14,11 +14,12 @@ import { UserAppPassword } from '@sync-in-server/backend/src/applications/users/
import { WEBDAV_BASE_PATH } from '@sync-in-server/backend/src/applications/webdav/constants/routes'
import { TWO_FA_HEADER_CODE, TWO_FA_HEADER_PASSWORD } from '@sync-in-server/backend/src/authentication/constants/auth'
import { TwoFaSetup } from '@sync-in-server/backend/src/authentication/interfaces/two-fa-setup.interface'
-import { L10N_LOCALE, L10nLocale, L10nTranslateDirective, L10nTranslatePipe } from 'angular-l10n'
+import { L10N_LOCALE, L10nLocale, L10nTranslateDirective, L10nTranslatePipe, L10nTranslationService } from 'angular-l10n'
import { BsModalRef } from 'ngx-bootstrap/modal'
import { ClipboardService } from 'ngx-clipboard'
import { Subscription } from 'rxjs'
import { filter, take } from 'rxjs/operators'
+import { i18nLanguageText } from '../../../../i18n/l10n'
import { InputPasswordComponent } from '../../../common/components/input-password.component'
import { PasswordStrengthBarComponent } from '../../../common/components/password-strength-bar.component'
import { StorageUsageComponent } from '../../../common/components/storage-usage.component'
@@ -53,6 +54,7 @@ import { UserAuthManageAppPasswordsDialogComponent } from './dialogs/user-auth-m
})
export class UserAccountComponent implements OnDestroy {
protected readonly locale = inject<L10nLocale>(L10N_LOCALE)
+ protected readonly i18nLanguageText = i18nLanguageText
protected readonly allNotifications = Object.values(USER_NOTIFICATION_TEXT)
protected readonly allOnlineStatus = USER_ONLINE_STATUS_LIST
protected readonly passwordMinLength = USER_PASSWORD_MIN_LENGTH
@@ -64,6 +66,7 @@ export class UserAccountComponent implements OnDestroy {
protected oldPassword: string
protected newPassword: string
protected readonly store = inject(StoreService)
+ protected readonly l10nTranslationService = inject(L10nTranslationService)
private readonly layout = inject(LayoutService)
protected languages = this.layout.getLanguages(true)
private readonly userService = inject(UserService)
diff --git a/frontend/src/i18n/l10n.ts b/frontend/src/i18n/l10n.ts
index 37c73f45..f5f95275 100755
--- a/frontend/src/i18n/l10n.ts
+++ b/frontend/src/i18n/l10n.ts
@@ -12,6 +12,8 @@ import frLocale from './fr.json'
export const i18nAsset: any = { en: enLocale, fr: frLocale }
+export const i18nLanguageText = { auto: 'Auto', en: 'English', fr: 'Français' }
+
export const l10nConfig: L10nConfig = {
format: 'language',
providers: [{ name: 'app', asset: i18nAsset }],
@@ -20,8 +22,8 @@ export const l10nConfig: L10nConfig = {
keySeparator: '|',
defaultLocale: { language: 'en' },
schema: [
- { locale: { language: 'en' }, dir: 'ltr', text: 'United States' },
- { locale: { language: 'fr' }, dir: 'ltr', text: 'France' }
+ { locale: { language: 'en' }, dir: 'ltr' },
+ { locale: { language: 'fr' }, dir: 'ltr' }
]
}
diff --git a/frontend/src/styles/components/_notifications.scss b/frontend/src/styles/components/_notifications.scss
index 012be25c..4abe04a4 100644
--- a/frontend/src/styles/components/_notifications.scss
+++ b/frontend/src/styles/components/_notifications.scss
@@ -15,6 +15,7 @@
.ngx-toastr {
background-color: rgba(0, 0, 0, .9);
+ min-width: 250px;
width: auto !important;
}
diff --git a/scripts/unused_translations.js b/scripts/unused_translations.js
index 309fc089..c955abb2 100644
--- a/scripts/unused_translations.js
+++ b/scripts/unused_translations.js
@@ -9,24 +9,23 @@
* Script: unused_translations.js
*
* Purpose:
- * - Read frontend/i18n/fr.json
- * - Extract and flatten all keys (dot notation, e.g., "section.sub.title")
+ * - Read one or many translation JSON files
+ * - Read top-level keys only (no flattening)
* - Search each key across all .ts and .html files of the project
- * - Matches must be for the full phrase (no partial substring) and case-insensitive
- * - Print the list of unused keys
+ * - Matches must be for the full phrase (no partial substring)
+ * - Print the list of unused keys per translation file
*
* Usage:
* - node scripts/unused_translations.js
- * - Options:
- * --print-used Also print found keys with first occurrence
- * --root=<path> Project root path (default: process.cwd())
- * --translations=<p> Path to translation file (default: frontend/i18n/fr.json)
- * --include=<path> Start directory for scanning files (default: project root)
- * --quiet Reduced output (only print unused keys)
+ * - node scripts/unused_translations.js --i18n=<path>
+ * <path> can be:
+ * - a directory containing .json files (non-recursive)
+ * - a specific .json file
+ * Default: frontend/src/i18n
*
* Notes:
* - Word boundaries are adapted to i18n keys (allowed characters: [A-Za-z0-9_.-]).
- * - Ignored directories: node_modules, .git, dist, build, out, coverage, tmp, .idea, .vscode
+ * - Ignored directories: all directories that starts with '.' and node_modules, dist, build, out, coverage, tmp
*/
const fs = require('fs')
@@ -42,18 +41,28 @@ const argMap = new Map(
})
)
-const PROJECT_ROOT = path.resolve(process.cwd(), argMap.get('root') || '')
-const TRANSLATION_FILE = path.resolve(PROJECT_ROOT, argMap.get('translations') || 'frontend/src/i18n/fr.json')
-// Directory to start scanning from (defaults to project root)
-const SEARCH_ROOT = path.resolve(PROJECT_ROOT, argMap.get('include') || '')
+const PROJECT_ROOT = process.cwd()
+// Single option: --i18n=<dir or file>. Default to the standard i18n directory.
+const I18N_PATH = path.resolve(PROJECT_ROOT, argMap.get('i18n') || 'frontend/src/i18n')
-const PRINT_USED = Boolean(argMap.get('print-used'))
-const QUIET = Boolean(argMap.get('quiet'))
-
-const IGNORED_DIRS = new Set(['node_modules', '.git', 'dist', 'build', 'out', 'coverage', 'tmp', '.idea', '.vscode'])
+const IGNORED_DIRS = new Set([
+ 'node_modules',
+ 'dist',
+ 'build',
+ 'out',
+ 'coverage',
+ 'release',
+ 'tmp',
+ 'scripts',
+ 'coverage',
+ 'logs',
+ 'migrations',
+ 'docker',
+ 'environment'
+])
// Static list of keys to ignore when reporting unused translations.
-// Add exact key strings as they appear in fr.json.
+// Add exact key strings as they appear in the translation JSONs.
const IGNORE_UNUSED_KEYS = ['Sync already exists', 'nb_elements', 'one_message', 'nb_messages']
function readJson(filePath) {
@@ -66,22 +75,6 @@ function readJson(filePath) {
}
}
-function flattenKeys(obj, prefix = '') {
- const keys = []
- const isObject = (v) => v && typeof v === 'object' && !Array.isArray(v)
-
- for (const [k, v] of Object.entries(obj || {})) {
- const current = prefix ? `${prefix}.${k}` : k
- if (isObject(v)) {
- keys.push(...flattenKeys(v, current))
- } else {
- // Add final leaf key (we don't filter by value type)
- keys.push(current)
- }
- }
- return keys
-}
-
function walkFiles(startDir) {
const result = []
function walk(dir) {
@@ -95,6 +88,7 @@ function walkFiles(startDir) {
for (const entry of entries) {
const fullPath = path.join(dir, entry.name)
if (entry.isDirectory()) {
+ if (entry.name.startsWith('.')) continue
if (IGNORED_DIRS.has(entry.name)) continue
walk(fullPath)
} else if (entry.isFile()) {
@@ -185,57 +179,83 @@ function findUsageMap(keys, files) {
return { used: Array.from(used), unused, where }
}
+function resolveTranslationTargets(entryPath) {
+ if (!fs.existsSync(entryPath)) {
+ console.error(`Error: path not found: ${entryPath}`)
+ process.exit(1)
+ }
+ const stat = fs.statSync(entryPath)
+ if (stat.isFile()) {
+ if (!entryPath.toLowerCase().endsWith('.json')) {
+ console.error(`Error: file is not a .json: ${entryPath}`)
+ process.exit(1)
+ }
+ return [entryPath]
+ }
+ if (stat.isDirectory()) {
+ const files = fs
+ .readdirSync(entryPath, { withFileTypes: true })
+ .filter((e) => e.isFile() && e.name.toLowerCase().endsWith('.json'))
+ .map((e) => path.join(entryPath, e.name))
+ .sort()
+ if (files.length === 0) {
+ console.error(`Error: no .json files found in directory: ${entryPath}`)
+ process.exit(1)
+ }
+ return files
+ }
+ console.error(`Error: unsupported path type: ${entryPath}`)
+ process.exit(1)
+}
+
function main() {
const startTs = Date.now()
- if (!fs.existsSync(TRANSLATION_FILE)) {
- console.error(`Error: translation file not found: ${TRANSLATION_FILE}`)
- process.exit(1)
+ const translationFiles = resolveTranslationTargets(I18N_PATH)
+ const searchRoot = PROJECT_ROOT
+ const files = walkFiles(searchRoot)
+
+ console.log('Translations analysis')
+ console.log(`- Project root: ${PROJECT_ROOT}`)
+ console.log(`- Scanned directory: ${searchRoot}`)
+ console.log(`- .ts/.html files scanned: ${files.length}`)
+ console.log(`- Translation sources:`)
+ for (const f of translationFiles) {
+ console.log(` - ${f}`)
}
- const dict = readJson(TRANSLATION_FILE)
- const keys = flattenKeys(dict).sort()
+ let totalUnused = 0
- const searchRoot = fs.existsSync(SEARCH_ROOT) ? SEARCH_ROOT : PROJECT_ROOT
- const files = walkFiles(searchRoot)
+ for (const tFile of translationFiles) {
+ const dict = readJson(tFile)
+ const keys = Object.keys(dict || {}).sort()
- const { used, unused, where } = findUsageMap(keys, files)
+ const { used, unused /*, where */ } = findUsageMap(keys, files)
- if (!QUIET) {
- console.log('Translations analysis (fr.json)')
- console.log(`- Project root: ${PROJECT_ROOT}`)
- console.log(`- Translations file: ${TRANSLATION_FILE}`)
- console.log(`- Scanned directory: ${searchRoot}`)
- console.log(`- .ts/.html files scanned: ${files.length}`)
+ console.log(`\n[${tFile}]`)
console.log(`- Total keys: ${keys.length}`)
console.log(`- Keys found: ${used.length}`)
console.log(`- Keys ignored: ${IGNORE_UNUSED_KEYS.length}`)
console.log(`- Unused keys: ${unused.length}`)
- if (PRINT_USED) {
- console.log('\nUsed keys (first occurrence):')
- for (const k of used) {
- console.log(` - ${k} @ ${where.get(k)}`)
+
+ if (unused.length) {
+ console.log('Unused keys:')
+ for (const k of unused) {
+ console.log(` - ${k}`)
}
+ } else {
+ console.log('No unused keys detected.')
}
- }
- if (unused.length) {
- console.log('\nUnused keys:')
- for (const k of unused) {
- console.log(` - ${k}`)
- }
- } else {
- console.log('\nNo unused keys detected.')
+ totalUnused += unused.length
}
- if (!QUIET) {
- const ms = Date.now() - startTs
- console.log(`\nDone in ${ms} ms`)
- }
+ const ms = Date.now() - startTs
+ console.log(`\nDone in ${ms} ms`)
// Exit 0 even if there are unused keys (audit script).
// To fail CI when unused keys exist:
- // process.exit(unused.length ? 1 : 0);
+ // process.exit(totalUnused ? 1 : 0);
}
if (require.main === module) {