Skip to content

Commit

Permalink
fix: streamline locale handling and UI documentation per PR feedback (B…
Browse files Browse the repository at this point in the history
…larc#309)

- Simplify locale display format in prompts to use English language names
- Remove redundant Elvis operator in locale retrieval
- Replace deprecated Locale constructor with forLanguageTag()
- Add collator comments explaining locale-aware sorting rationale
- Include contextual help about language display differences
  • Loading branch information
Canario5 authored and Blarc committed Feb 18, 2025
1 parent f5c5ff0 commit 969114b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ object AICommitsUtils {
fun constructPrompt(promptContent: String, diff: String, branch: String, hint: String?, project: Project): String {
var content = promptContent
val locale = project.service<ProjectSettings>().locale
// lang format: "Language name in English + (ISO 639 lang code) + – + native language name in IDE's locale"; example "French (fr) – français"
content = content.replace("{locale}", "${locale.getDisplayLanguage(Locale.ENGLISH)} (${locale.language}) \u2013 ${locale.getDisplayLanguage(locale)}")
content = content.replace("{locale}", locale.getDisplayLanguage(Locale.ENGLISH))
content = content.replace("{branch}", branch)
content = replaceHint(content, hint)

Expand Down Expand Up @@ -178,6 +177,6 @@ object AICommitsUtils {
}

fun getIDELocale(): Locale {
return DynamicBundle.getLocale() ?: Locale.getDefault()
return DynamicBundle.getLocale()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AICommitsListCellRenderer : DefaultListCellRenderer() {
is Locale -> {
val ideLocale = AICommitsUtils.getIDELocale()
// lang format: "Language name in IDE's locale + (ISO 639 lang code)"; example for Spanish in IDE "francés (fr)", for IDE in German "Französisch (fr)"
text = "${Locale(value.language).getDisplayName(ideLocale)} (${value.language})"
text = "${Locale.forLanguageTag(value.language).getDisplayLanguage(ideLocale)} (${value.language})"
}

is Prompt -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class AppSettingsConfigurable(val project: Project, cs: CoroutineScope) : BoundC
label(message("settings.locale")).widthGroup("labelPrompt")
val ideLocale = AICommitsUtils.getIDELocale()

// Configures locale-aware text comparator for proper language name sorting
// Without a Collator, we would get incorrect sorting based on raw Unicode values
val collator = Collator.getInstance(ideLocale).apply {
strength = Collator.TERTIARY
decomposition = Collator.CANONICAL_DECOMPOSITION
Expand All @@ -100,6 +102,8 @@ class AppSettingsConfigurable(val project: Project, cs: CoroutineScope) : BoundC
.widthGroup("input")
.bindItem(getter = { projectSettings.locale }, setter = { setActiveLocale(it)} )

contextHelp(message("settings.locale.contextHelp"))

browserLink(message("settings.more-prompts"), AICommitsBundle.URL_PROMPTS_DISCUSSION.toString())
.align(AlignX.RIGHT)
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages/AiCommitsBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name=AI Commits
settings.title=Settings
settings.general.group.title=AI Commits
settings.locale=Locale
settings.locale.contextHelp=Listed locales appear in the IDE's language. Prompts use English locales (e.g., German, French, etc.).
settings.prompt=Prompt
settings.report-bug=Report bug
settings.verifyToken=Verify
Expand Down

0 comments on commit 969114b

Please sign in to comment.