Skip to content

feat: multi-language support - #357

Closed
eramitgupta wants to merge 8 commits into
dev-null-sh:productionfrom
eramitgupta:feat/multi-language
Closed

eramitgupta wants to merge 8 commits into
dev-null-sh:productionfrom
eramitgupta:feat/multi-language

Conversation

@eramitgupta

@eramitgupta eramitgupta commented Oct 17, 2026 •

Copy link
Copy Markdown

Multi-language support

devnull can now be used in 10 languages. English stays the default; anyone can switch under Settings → Appearance → Language, and the page re-renders in the new language without a full reload. Commits, names and bios stay in the language they were written in.

Code Language
en English (default)
hi हिन्दी
es Español
fr Français
de Deutsch
pt_BR Português (Brasil)
zh_CN 中文(简体)
ja 日本語
ru Русский
ko 한국어

All are left-to-right, so the layout doesn't change. Right-to-left languages (Arabic, Urdu) are not included.


The package

Translations use erag/laravel-lang-sync-inertia (Laravel) and @erag/lang-sync-inertia (frontend), set up the way the package's own skill describes:

  1. Source: UI strings live in Laravel PHP language files, lang/{locale}/{group}.php.
  2. Export: php artisan erag:generate-lang writes them to resources/js/lang/{locale}/{group}.json.
  3. Sharing: the package's service provider loads the JSON for app()->getLocale() and shares it on every Inertia response as the lang prop. No middleware or syncLangFiles() call is needed for these groups.
  4. Frontend: components read translations with the package's React hook.

Config is published at config/inertia-lang.php (erag:install-lang) and keeps the defaults: lang_path = lang/, output_lang = resources/js/lang.

Groups

Group Covers
nav Sidebar nav, aside, user menu, keyboard shortcuts, search dialog, who to follow
settings Settings pages: profile, appearance, language, lane, pastéis mode, safety, terminal, scheduled commits, delete account
search Search page
composer Commit and reply composers, mentions, image picker, polls, link cards, secret warning, quote dialog
commits Commit cards, threads, feed, images and viewer, polls, star / pin / save / report / delete, undo toast
log Log tabs, new-commits banner, empty states
users Profile, connections, saved, user preview card, follow, safety menu, achievements, activity graph
notifications Notifications page

How the language is chosen

  • App\Enums\Locale: the supported languages. label() gives each one's name in its own language.
  • locale cookie: stores the choice, like appearance. Added to encryptCookies(except: ...) because the browser writes it.
  • App\Http\Middleware\HandleLocale: reads the cookie and calls App::setLocale() when it's a supported language; anything else falls back to English. It only sets the locale and shares nothing.
  • HandleInertiaRequests: shares locale (current) and locales ({ value, label }[]) for the switcher.
  • LanguageSelect: the dropdown on the Appearance page. It writes the cookie, updates <html lang>, and calls router.reload() so the server returns the page and lang prop in the new language.

Guide: using translations in a component

import { useLang } from '@erag/lang-sync-inertia/react';

export function FollowButton({ name, count }: Props) {
    const { __, transChoice } = useLang();

    return (
        <>
            <button>{__('users.follow.follow')}</button>
            <span>{__('users.preview.title', { name })}</span>
            <span>{transChoice('users.profile.followers', count)}</span>
        </>
    );
}
  • Import from @erag/lang-sync-inertia/react, not the package root. The root entry also loads the Vue and Svelte builds; the skill recommends the framework entry.
  • Use useLang(), not reactLang() / lang(). They are the same hook, but the React Compiler only treats use* names as hooks. With reactLang() it cached the result, so after switching languages part of the page kept the old one.
  • Call it inside the component body (it uses usePage()). Helpers outside components take __ / transChoice as a parameter from the caller.
  • Keys are full paths: group.section.key. A missing key renders the key itself, so every key you use must exist in lang/en.

Placeholders and plurals

// lang/en/users.php
'preview' => [
    'title' => 'About :name',
],
'profile' => [
    'followers' => ':count follower|:count followers',
    'followers_label' => 'follower|followers', // when the number is rendered separately
],
'groups' => [
    'stars' => '{0} No stars|{1} One star|[2,*] :count stars',
],
  • Placeholders are Laravel-style :name.
  • transChoice picks the first form for 1 and the last otherwise, and supports Laravel intervals ({0}, [2,4], [5,*]). Russian uses intervals for its three forms; Chinese, Japanese and Korean repeat one form on both sides of |.

Sentences around links or elements

__() returns a string, so a sentence containing a link is split into fragments (*_before, *_link, *_after) that each language fills in so it reads naturally.


Guide: adding or changing text

  1. Add or edit the key in lang/en/{group}.php.
  2. Add the same key to every other lang/{locale}/{group}.php.
  3. Regenerate the JSON:
    php artisan erag:generate-lang
  4. Commit the PHP files and the regenerated JSON together.

tests/Feature/TranslationsTest.php fails if a language is missing a key, has an extra or empty one, changes the :placeholders of a line, or if the JSON is out of date with the PHP files.

Guide: adding a language

  1. Add a case to App\Enums\Locale with its native-name label() (and update LocaleTest).
  2. Create lang/{locale}/ with all 8 groups, translated, with the same keys as lang/en.
  3. Run php artisan erag:generate-lang and commit resources/js/lang/{locale}/.

The language then appears in the switcher automatically, and TranslationsTest covers it through the enum.


Other changes

  • Format check: resources/js/lang/** is excluded from vp fmt, like the generated Wayfinder folders, because erag:generate-lang writes 4-space JSON.
  • Tests: tests/draft-images.config.ts inlines @erag/lang-sync-inertia for vitest so usePage mocks reach the hook. Frontend tests that assert English text now pass a lang prop.
  • Undo toast: the toast renders outside the Inertia app, so AppLayout hands it translated labels via useUndoToastLabels().
  • SegmentedControl: keys and view-transition names now come from option.value instead of the translated label.
  • PageTabs: new optional name prop, a stable English name for the indicator's view-transition, so translated labels don't change it.
  • formatDayLabel(): takes optional translated "Today" / "Yesterday" labels.
  • Button widths: buttons whose label changes (Show/Hide replies, Vote/Voting, Undo/Restoring, Pin/Unpin, Quote/Quoting…, Copy/Copied) got a min-w-* so translations don't shift the layout.

Not translated yet

  • Pages: welcome, onboarding, moderation, operations, error page.
  • Server-side text: flash toasts and validation messages from Laravel (__() in PHP).
  • Dates: the short relative times (3m, 2h, 5d); full dates use the browser's locale.
  • Plural verbs: "Ana and 3 others followed you" uses one verb form, so the verb doesn't agree in es, fr, de, pt and ru.
  • Kept on purpose: brand and git-style tokens (devnull, /dev/null, stash@{0}, HEAD, fatal:), @handles, hashes, keyboard keys and code samples.

Testing

  • Lint, tsc, JS unit tests, PHPStan, Rector, Pint, 100% type coverage and bun run build pass.
  • New PHP tests:
    • LocaleTest: languages and native names.
    • HandleLocaleTest: cookie, unsupported value, non-string value.
    • HandleInertiaRequestsTest: locale and locales props.
    • TranslationsTest: key and placeholder parity, JSON up to date, and a page rendered in Hindi from the cookie.
  • Not run locally: the PHP suite needs PostgreSQL with pgvector, so CI runs these tests for the first time.
  • Browser: switched English → Hindi → Spanish → Japanese live. No raw keys on log, trending, profile, notifications, search, saved, and the profile, terminal, safety and appearance settings pages.
image image image image image

@eramitgupta eramitgupta changed the title feat: multi-language support with erag/laravel-lang-sync-inertia feat: multi-language support Oct 17, 2026
eramitgupta and others added 4 commits October 17, 2026 23:05
The page now ships its UI translations, which include the generic "replying to" copy, so assert on the parent's handle instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@prateekbhujel

Copy link
Copy Markdown
Contributor

Hey @eramitgupta! Awesome work on bringing multi-language support to /dev/null! 🚀

Just wanted to share two quick things that might help get this merged smoothly:

  1. Why the CI tests job is failing:
    In tests/Feature/Controllers/CommitControllerTest.php:811, the test asserts ->assertDontSee('replying to') to verify that an unavailable parent isn't mentioned in the link preview title/description. Because commits.card.replying_to ('replying to @:username') is injected into Inertia's data-page JSON dictionary in the HTML body, the assertion catches the translation key.
    Refining line 811 to:

    ->assertDontSee('replying to @taylorotwell')

    preserves the exact link preview assertion intent (matching line 798) and gets the test suite to 100% green!

  2. Nepali (नेपाली / ne) Language Support:
    I also prepared complete Nepali language support across all 8 translation groups, with generated JSON and 100% test parity. I opened a PR against your branch here: feat: add Nepali language support and fix link preview test eramitgupta/dev-null.sh#1 so you can merge it directly in if you'd like to include it in this PR! 🙌

eramitgupta and others added 3 commits October 17, 2026 23:26
…nguage

Translates the new upstream copy too: the image drop overlay, the quote reply labels, the GIF-free image error and the singular pastel count.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
feat: add Nepali language support and fix link preview test
…nguage

Translates upstream's custom lane color option, and completes the Nepali files with the keys added since that PR branched (quoting labels, image drop overlay, GIF-free image error, singular pastel count).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@xHeaven

xHeaven commented Oct 18, 2026

Copy link
Copy Markdown
Member

@nunomaduro This PR touches new third-party dependencies and configuration. Could you take a look?

@xHeaven

xHeaven commented Oct 22, 2026

Copy link
Copy Markdown
Member

Note

This message is generated by gpt-6.1-sol on behalf of xHeaven. It may contain errors—verify important details.

The secret scanner and its warnings have been removed in #999. The scanner warning and confirmation strings no longer need translation.

@nunomaduro

Copy link
Copy Markdown
Member

This out, hey, dude, I really appreciate all of your work on this. However, it does look too much in terms of files change, in terms of code, to actually just add multi-language support to the social media. We actually don't want that right now. It's a good idea in the future, but we want to table it for now because we really feel that it's just too soon to think about this. Thanks

@nunomaduro nunomaduro closed this Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants