Skip to content

feat(details): auto-translate README + release notes on open#635

Open
rainxchzed wants to merge 4 commits into
mainfrom
feat/auto-translate
Open

feat(details): auto-translate README + release notes on open#635
rainxchzed wants to merge 4 commits into
mainfrom
feat/auto-translate

Conversation

@rainxchzed
Copy link
Copy Markdown
Member

@rainxchzed rainxchzed commented May 18, 2026

Summary

  • Two new TweaksRepository prefs (auto_translate_enabled, auto_translate_target_lang) with KSafe migration entries.
  • Auto-translate repositories toggle in Tweaks → Translation section.
  • DetailsViewModel.maybeAutoTranslate kicks off TranslateAbout + TranslateWhatsNew once when readme and release description first load and the user's app language differs from the source.
  • Target resolution: explicit pref → app language → device locale.

Closes #423.

Test plan

  • Toggle on, open a repo with English README and Chinese app language → README + release notes auto-translate
  • Toggle off, same flow → no auto-translation
  • Compile both targets — ✓ verified

Summary by CodeRabbit

  • New Features

    • Auto-translate for READMEs and release notes with enable/disable toggle and language picker (select/reset).
    • Automatic conditional translation during initial content load, using explicit target, app language, or device language as fallback.
    • New UI strings and controls for configuring auto-translate.
  • Chores

    • Preferences added and migrated so auto-translate settings persist across updates.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 87964542-b49f-41d9-abd7-192f9a90f75e

📥 Commits

Reviewing files that changed from the base of the PR and between 540d521 and 552858c.

📒 Files selected for processing (3)
  • core/presentation/src/commonMain/composeResources/values/strings.xml
  • feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/DetailsViewModel.kt
  • feature/tweaks/presentation/src/commonMain/kotlin/zed/rainxch/tweaks/presentation/TweaksViewModel.kt
🚧 Files skipped from review as they are similar to previous changes (3)
  • feature/tweaks/presentation/src/commonMain/kotlin/zed/rainxch/tweaks/presentation/TweaksViewModel.kt
  • core/presentation/src/commonMain/composeResources/values/strings.xml
  • feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/DetailsViewModel.kt

Walkthrough

Adds persistent auto-translate preferences with UI controls and ViewModel wiring, and triggers conditional automatic translation of Details README and release notes during initial load.

Changes

Auto-translate Settings and Details Integration

Layer / File(s) Summary
Repository contract and persistence
core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/repository/TweaksRepository.kt, core/data/src/commonMain/kotlin/zed/rainxch/core/data/repository/TweaksRepositoryImpl.kt
TweaksRepository interface defines getters and setters for the auto-translate enabled flag and target language BCP 47 tag; TweaksRepositoryImpl persists both to KSafe storage with legacy migration entries and preference key constants.
UI state and action definitions
feature/tweaks/presentation/src/commonMain/kotlin/zed/rainxch/tweaks/presentation/TweaksState.kt, feature/tweaks/presentation/src/commonMain/kotlin/zed/rainxch/tweaks/presentation/TweaksAction.kt
TweaksState adds autoTranslateEnabled and autoTranslateTargetLang fields; TweaksAction adds OnAutoTranslateEnabledToggle and OnAutoTranslateTargetSelected variants for user interactions.
Tweaks ViewModel wiring
feature/tweaks/presentation/src/commonMain/kotlin/zed/rainxch/tweaks/presentation/TweaksViewModel.kt
TweaksViewModel initialization calls loadAutoTranslate() to collect repository flows and update state; onAction handler persists user toggles and target selections back to the repository.
Tweaks UI rendering and strings
core/presentation/src/commonMain/composeResources/values/strings.xml, feature/tweaks/presentation/src/commonMain/kotlin/zed/rainxch/tweaks/presentation/components/sections/Language.kt
String resources provide auto-translate labels; LanguageDropdown is made internal to support the auto-target selector.
Details auto-translation on load
feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/DetailsViewModel.kt
DetailsViewModel.loadInitial() calls maybeAutoTranslate() helper to check preferences, determine target language (explicit → app → device), and conditionally trigger translateContent for readme and release description while cancelling overlapping jobs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I found a tiny prefs patch in the hay,
A switch to wake words that wander and play.
Targets trimmed, defaults kept small,
Readmes now whisper in languages all.
Hop—translations hum when the settings call.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.41% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main feature: auto-translating README and release notes when opening a repository, which is the primary change across multiple files.
Linked Issues check ✅ Passed The PR implements the core requirement from #423: automatic translation of repository text (README and release notes) when opening a repo, respecting user-selected language preferences.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing auto-translation: repository preferences, UI toggles/selectors, ViewModel translation logic, and string resources are all in scope.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/auto-translate

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/DetailsViewModel.kt`:
- Around line 2898-2903: The explicit auto-translate target can be an empty
string and currently wins the fallback; change how `explicit` (and optionally
`app`) are derived so blank strings are treated as unset before computing
`target` — for example, in `DetailsViewModel` when calling
`tweaksRepository.getAutoTranslateTargetLang().first()` wrap the result with
`.takeIf { it.isNotBlank() }` (or use `ifBlank { null }`) so `explicit ?: app ?:
translationRepository.getDeviceLanguageCode()` only sees non-blank values,
ensuring app/device fallbacks occur as intended.

In
`@feature/tweaks/presentation/src/commonMain/kotlin/zed/rainxch/tweaks/presentation/components/sections/Translation.kt`:
- Around line 72-75: The AutoTranslate UI only exposes the enable switch; update
the AutoTranslateCard invocation to also pass the current target language and
selection callback so users can pick a repository auto-translate target;
specifically, add props for the selected language
(state.autoTranslateTargetLang) and a selection handler that calls
onAction(TweaksAction.OnAutoTranslateTargetSelected(it)), matching the
action/field names, and ensure the AutoTranslateCard component accepts and
forwards these props so the target-language path becomes reachable from this
screen.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f0d66b41-410a-4f20-aa08-b1d699399073

📥 Commits

Reviewing files that changed from the base of the PR and between 2c70263 and 0c79a47.

📒 Files selected for processing (8)
  • core/data/src/commonMain/kotlin/zed/rainxch/core/data/repository/TweaksRepositoryImpl.kt
  • core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/repository/TweaksRepository.kt
  • core/presentation/src/commonMain/composeResources/values/strings.xml
  • feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/DetailsViewModel.kt
  • feature/tweaks/presentation/src/commonMain/kotlin/zed/rainxch/tweaks/presentation/TweaksAction.kt
  • feature/tweaks/presentation/src/commonMain/kotlin/zed/rainxch/tweaks/presentation/TweaksState.kt
  • feature/tweaks/presentation/src/commonMain/kotlin/zed/rainxch/tweaks/presentation/TweaksViewModel.kt
  • feature/tweaks/presentation/src/commonMain/kotlin/zed/rainxch/tweaks/presentation/components/sections/Translation.kt

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 18, 2026

Greptile Summary

This PR wires up automatic translation of READMEs and release notes in the Details screen: two new TweaksRepository prefs (auto_translate_enabled, auto_translate_target_lang) are persisted with KSafe migration entries, a toggle + language picker are added to the Tweaks → Translation section, and DetailsViewModel.maybeAutoTranslate fires translateContent once on initial load when the detected source language differs from the resolved target.

  • TweaksRepositoryImpl and the domain interface are clean; blank/empty normalization and migration entries are handled correctly.
  • DetailsViewModel.maybeAutoTranslate includes source-language guards for both README and release notes (using readmeLanguage as a proxy for release-notes language), resolves the target via explicit pref → app language → device locale, and is idempotent via the translatedText == null check.
  • AutoTranslateCard in Translation.kt reuses LanguageDropdown from the app-language section, but that dropdown is backed by AppLanguages.ALL (13 languages) rather than SupportedLanguages.all (33 languages), making 20 valid translation targets (German, Dutch, Portuguese, Vietnamese, etc.) unselectable; two string resources (translation_auto_target, translation_auto_target_reset) are defined but never referenced.

Confidence Score: 4/5

The auto-translate toggle and DetailsViewModel logic are safe to merge; the explicit target picker silently omits 20 of 33 translation-supported languages, leaving those targets unreachable through the UI.

The repository layer and DetailsViewModel are correct. The language picker in AutoTranslateCard reuses LanguageDropdown, which is backed by AppLanguages.ALL (13 entries) instead of SupportedLanguages.all (33 entries). Users wanting to explicitly target German, Dutch, Portuguese, Vietnamese, or any of the other 14 languages not in AppLanguages cannot do so — the dropdown simply won't list them. That functional gap is a real, present defect in the translation-target selection path.

feature/tweaks/presentation/.../sections/Translation.kt — the LanguageDropdown reuse restricts the auto-translate target picker to app-UI languages only.

Important Files Changed

Filename Overview
feature/tweaks/presentation/src/commonMain/kotlin/zed/rainxch/tweaks/presentation/components/sections/Translation.kt Adds AutoTranslateCard with a toggle and LanguageDropdown for the target; LanguageDropdown is constrained to AppLanguages.ALL (13 languages) instead of SupportedLanguages.all (33), blocking explicit selection of 20 valid translation targets; "Follow system" label is semantically wrong for the auto-translate null case.
feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/DetailsViewModel.kt Adds maybeAutoTranslate: reads three prefs sequentially, guards README branch on readmeLanguage, mirrors that guard for release notes using readmeLanguage as a proxy. Logic is sound; the source-language guard for both branches is present.
core/presentation/src/commonMain/composeResources/values/strings.xml Adds 6 new strings for auto-translate; translation_auto_target and translation_auto_target_reset are defined but never referenced in code.
core/data/src/commonMain/kotlin/zed/rainxch/core/data/repository/TweaksRepositoryImpl.kt Implements getAutoTranslateEnabled/setAutoTranslateEnabled and getAutoTranslateTargetLang/setAutoTranslateTargetLang with correct KSafe migration entries; blank/empty normalization is handled properly.
core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/repository/TweaksRepository.kt Clean interface additions for auto-translate prefs with accurate KDoc; no issues.
feature/tweaks/presentation/src/commonMain/kotlin/zed/rainxch/tweaks/presentation/TweaksViewModel.kt loadAutoTranslate correctly launches two collectors; action handlers for OnAutoTranslateEnabledToggle and OnAutoTranslateTargetSelected delegate cleanly to the repository.
feature/tweaks/presentation/src/commonMain/kotlin/zed/rainxch/tweaks/presentation/components/sections/Language.kt LanguageDropdown visibility widened from private to internal to allow reuse in Translation.kt; no other logic changed.
feature/tweaks/presentation/src/commonMain/kotlin/zed/rainxch/tweaks/presentation/TweaksAction.kt Two new sealed actions added cleanly; no issues.
feature/tweaks/presentation/src/commonMain/kotlin/zed/rainxch/tweaks/presentation/TweaksState.kt Two new state fields with correct defaults added; no issues.

Sequence Diagram

sequenceDiagram
    participant U as User
    participant DVM as DetailsViewModel
    participant TR as TweaksRepository
    participant TLR as TranslationRepository
    participant S as DetailsState

    U->>DVM: Open repository details
    DVM->>S: _state.update(readmeMarkdown, readmeLanguage, selectedRelease, ...)
    DVM->>DVM: maybeAutoTranslate(readmeBody, releaseDescription)
    DVM->>TR: getAutoTranslateEnabled().first()
    alt "enabled = false"
        DVM-->>DVM: return (no-op)
    else "enabled = true"
        DVM->>TR: getAutoTranslateTargetLang().first()
        DVM->>TR: getAppLanguage().first()
        DVM->>TLR: getDeviceLanguageCode()
        note over DVM: target = explicit ?: app ?: deviceLocale
        alt "readmeBody not blank AND translatedText == null AND sourceLang != target"
            DVM->>TLR: translate(readmeBody, target)
            TLR-->>DVM: TranslationResult
            DVM->>S: "copy(aboutTranslation = TranslationState(isShowingTranslation=true, ...))"
        end
        alt "releaseDescription not blank AND translatedText == null AND readmeLanguage != target"
            DVM->>TLR: translate(releaseDescription, target)
            TLR-->>DVM: TranslationResult
            DVM->>S: "copy(whatsNewTranslation = TranslationState(isShowingTranslation=true, ...))"
        end
    end
Loading

Fix All in Claude Code

Reviews (4): Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." | Re-trigger Greptile

Comment on lines +136 to +141
selectedTag = targetLanguageTag,
onLanguageSelected = onTargetSelected,
)
if (targetLanguageTag == null && !appLanguageTag.isNullOrBlank()) {
Spacer(Modifier.height(6.dp))
Text(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Auto-translate picker limited to app-UI languages (13 of 33 supported)

LanguageDropdown is built over AppLanguages.ALL, which contains only the 13 languages the app ships UI translations for. The translation service, however, supports 33 languages (SupportedLanguages.all). As a result, a user who wants to auto-translate READMEs into German (de), Dutch (nl), Portuguese (pt), Ukrainian (uk), Vietnamese (vi), or any of the other 14 missing languages cannot select those targets through this picker — the dropdown simply won't offer them. The device-locale fallback path can still reach these languages silently, but explicit selection is broken for roughly 60% of the supported translation targets.

Fix in Claude Code

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.

Вопрос - на счёт перевода.

1 participant