Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ env:
NDK_VERSION: "29.0.14206865"

jobs:
i18n:
name: Localizable app and plugin text
if: github.event_name == 'pull_request'
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- run: python3 tools/check_i18n.py --base "$BASE" --check-existing
env:
BASE: ${{ github.event.pull_request.base.sha }}

rust:
name: Rust (format, clippy, tests)
if: ${{ !github.event.repository.private || github.event_name == 'workflow_dispatch' }}
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,31 @@ Build time dependencies:

*Builds are only tested on Windows 11.*

## Translations

Pass new app labels, accessibility text, and notices through `tr`. Use a full message
with numbered placeholders for values that may move in another language. Keep saved
keys, brush settings, and artwork names out of the lookup.

Run `python tools/check_i18n.py --catalog` to list the English messages. The
App translations are in `crates/core/src/i18n/`. Edit the second string in each
pair and keep its placeholders. Register new language catalogs
in `crates/core/src/i18n.rs` using language tags such as `pt-BR`. Missing entries
use the parent language or English.
Desktop follows the system language. Set `PROCRAFT_LANGUAGE` to test a language
for one run.

Android generates its localized widget strings from `android/app/build.gradle.kts`.
`ios/localize.sh` generates the system Settings, bundle, and widget strings for
iPad. The pull request check flags new hardcoded text in app and plugin sources
and checks that the app and bundled plugin catalogs cover their messages.

Plugin manifest labels and descriptions are messages as written. For text produced by
plugin code, use `kit::message!` on panel labels, choices, and notices. Put translations
in the plugin manifest's `locales` object, keyed by language tag, then by the English
message. For panel text and notices with values, use `kit::message!("Value {0}", value)`
and declare plugin interface 24 or later. The app reads each plugin's own catalog.

<br>

## License
Expand Down
109 changes: 109 additions & 0 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,113 @@ android {
}
}

abstract class LocalizedResources : DefaultTask() {
@get:OutputDirectory
abstract val outputDir: DirectoryProperty

@TaskAction
fun writeResources() {
writeWidgetStrings("ar", "آخر عمل فني", "يفتح ProCraft على آخر عمل فني عدّلته.")
writeWidgetStrings(
"bn",
"সাম্প্রতিক শিল্পকর্ম",
"শেষ যে শিল্পকর্মে কাজ করেছিলেন, ProCraft সেটি খুলবে।"
)
writeWidgetStrings(
"pt-rBR",
"Arte recente",
"Abre o ProCraft na última arte em que você trabalhou."
)
writeWidgetStrings("de", "Letztes Bild", "Öffnet das zuletzt bearbeitete Bild in ProCraft.")
writeWidgetStrings("es", "Última obra", "Abre en ProCraft la última obra que editaste.")
for (qualifier in listOf("tl", "b+fil")) {
writeWidgetStrings(qualifier, "Huling gawa", "Binubuksan sa ProCraft ang huling gawang in-edit mo.")
}
writeWidgetStrings(
"fr",
"Dernière création",
"Ouvre dans ProCraft la dernière création sur laquelle vous avez travaillé."
)
writeWidgetStrings("hi", "पिछली कलाकृति", "ProCraft में पिछली बार संपादित की गई कलाकृति खोलता है।")
// Older Android versions look for Indonesian resources under "in".
for (qualifier in listOf("in", "b+id")) {
writeWidgetStrings(qualifier, "Karya terakhir", "Membuka karya yang terakhir Anda kerjakan di ProCraft.")
}
writeWidgetStrings("it", "Ultima opera", "Apre in ProCraft l\\'ultima opera su cui hai lavorato.")
writeWidgetStrings("ja", "最近の作品", "ProCraftで最後に編集した作品を開きます。")
writeWidgetStrings("ko", "최근 작품", "ProCraft에서 마지막으로 편집한 작품을 엽니다.")
writeWidgetStrings("mr", "शेवटची कलाकृती", "ProCraft मध्ये तुम्ही शेवटी संपादित केलेली कलाकृती उघडते.")
writeWidgetStrings("ms", "Karya terakhir", "Membuka karya yang kali terakhir anda sunting dalam ProCraft.")
writeWidgetStrings("b+pa+Guru", "ਆਖਰੀ ਰਚਨਾ", "ProCraft ਵਿੱਚ ਪਿਛਲੀ ਵਾਰ ਸੋਧੀ ਰਚਨਾ ਖੋਲ੍ਹਦਾ ਹੈ।")
writeWidgetStrings("pl", "Ostatnia praca", "Otwiera ostatnią edytowaną pracę w ProCraft.")
writeWidgetStrings("ru", "Последняя работа", "Открывает в ProCraft работу, которую вы редактировали последней.")
writeWidgetStrings("sw", "Mchoro wa mwisho", "Hufungua ProCraft kwenye mchoro uliohariri mara ya mwisho.")
writeWidgetStrings("ta", "அண்மைய படைப்பு", "ProCraft இல் கடைசியாகத் திருத்திய படைப்பைத் திறக்கும்.")
writeWidgetStrings("te", "ఇటీవలి చిత్రం", "మీరు చివరిగా సవరించిన చిత్రాన్ని ProCraftలో తెరుస్తుంది.")
writeWidgetStrings("th", "ผลงานล่าสุด", "เปิดผลงานที่คุณแก้ไขล่าสุดใน ProCraft")
writeWidgetStrings("tr", "Son çalışma", "ProCraft son düzenlediğiniz çalışmayı açar.")
writeWidgetStrings("uk", "Остання робота", "Відкриває в ProCraft роботу, яку ви редагували останньою.")
writeWidgetStrings("ur", "حالیہ فن پارہ", "ProCraft میں وہ فن پارہ کھولتا ہے جس پر آپ نے آخری بار کام کیا تھا۔")
writeWidgetStrings("vi", "Tác phẩm gần đây", "Mở tác phẩm bạn chỉnh sửa gần nhất trong ProCraft.")
writeWidgetStrings("b+zh+Hans", "最近的作品", "打开 ProCraft 中上次编辑的作品。")
writeWidgetStrings("b+zh+Hant", "最近的作品", "在 ProCraft 中開啟上次編輯的作品。")
val locales = outputDir.file("xml/procraft_locales.xml").get().asFile
locales.parentFile.mkdirs()
locales.writeText(
"""
<?xml version="1.0" encoding="utf-8"?>
<locale-config xmlns:android="http://schemas.android.com/apk/res/android">
<locale android:name="en" />
<locale android:name="ar" />
<locale android:name="bn" />
<locale android:name="de" />
<locale android:name="es" />
<locale android:name="es-419" />
<locale android:name="es-ES" />
<locale android:name="fil" />
<locale android:name="fr" />
<locale android:name="hi" />
<locale android:name="id" />
<locale android:name="it" />
<locale android:name="ja" />
<locale android:name="ko" />
<locale android:name="mr" />
<locale android:name="ms" />
<locale android:name="pa-Guru" />
<locale android:name="pl" />
<locale android:name="pt-BR" />
<locale android:name="ru" />
<locale android:name="sw" />
<locale android:name="ta" />
<locale android:name="te" />
<locale android:name="th" />
<locale android:name="tr" />
<locale android:name="uk" />
<locale android:name="ur" />
<locale android:name="vi" />
<locale android:name="zh-Hans" />
<locale android:name="zh-Hant" />
</locale-config>
""".trimIndent() + "\n"
)
}

private fun writeWidgetStrings(qualifier: String, name: String, description: String) {
val strings = outputDir.file("values-$qualifier/strings.xml").get().asFile
strings.parentFile.mkdirs()
strings.writeText(
"""
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">ProCraft</string>
<string name="widget_recent_name">$name</string>
<string name="widget_recent_description">$description</string>
</resources>
""".trimIndent() + "\n"
)
}
}

androidComponents {
onVariants { variant ->
val name = variant.name.replaceFirstChar { it.uppercase() }
Expand All @@ -208,6 +315,8 @@ androidComponents {
}
variant.sources.jniLibs?.addGeneratedSourceDirectory(cargoBuild, CargoNdkBuild::outputDir)
variant.sources.java?.addGeneratedSourceDirectory(bindgen, UniffiBindgen::outputDir)
val localized = tasks.register<LocalizedResources>("localizedResources$name")
variant.sources.res?.addGeneratedSourceDirectory(localized, LocalizedResources::outputDir)
}
}

Expand Down
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
android:maxSdkVersion="28" />

<application
android:name=".ProCraftApplication"
android:allowBackup="false"
android:enableOnBackInvokedCallback="true"
android:largeHeap="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:localeConfig="@xml/procraft_locales"
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="false"
android:theme="@style/Theme.ProCraft">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.github.artcraftandroid.procraft

import android.app.Application
import android.content.res.Configuration
import io.github.artcraftandroid.procraft.core.configureAppLanguage

class ProCraftApplication : Application() {
override fun onCreate() {
super.onCreate()
updateLanguage(resources.configuration)
}

override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
updateLanguage(newConfig)
}
}

private var preferred = emptyList<String>()
@Volatile private var messages = emptyMap<String, String>()
private val slot = Regex("\\{([0-9]+)}")

internal fun updateLanguage(configuration: Configuration) {
val locales = configuration.locales
val tags = List(locales.size()) { locales[it].toLanguageTag() }
if (tags == preferred) return
messages = configureAppLanguage(tags)
preferred = tags
}

internal fun tr(source: String): String = messages[source] ?: source

internal fun message(source: String): String = source

internal fun tr(source: String, vararg args: Any?): String =
slot.replace(tr(source)) { match ->
val index = match.groupValues[1].toIntOrNull()
if (index != null && index < args.size) args[index].toString() else match.value
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge(SystemBarStyle.dark(Color.TRANSPARENT), SystemBarStyle.dark(Color.TRANSPARENT))
super.onCreate(savedInstanceState)
updateLanguage(resources.configuration)
// the log's file first, so that what follows is in it
AppLog.start(this)
// which graphics backend the app is trying, kept before the model (made at its first use
Expand All @@ -86,6 +87,7 @@ class MainActivity : ComponentActivity() {
vm.pickBrushFile = brushPickerOpener
// made here, not inside the flow's read-only snapshot, where its setup can't write state
val model = vm
model.refreshBlendLabels()
// laid out left to right in every language, as the original is: a right-to-left one
// (Arabic, Hebrew) would otherwise mirror the bars
setContent {
Expand Down Expand Up @@ -297,10 +299,10 @@ class MainActivity : ComponentActivity() {
val items = group.rows.flatMap { row ->
row.combos.mapNotNull { c ->
val (code, modifiers) = systemShortcutKeys(c.key, c.command, c.shift, c.alt) ?: return@mapNotNull null
android.view.KeyboardShortcutInfo(row.does, code, modifiers)
android.view.KeyboardShortcutInfo(tr(row.does), code, modifiers)
}
}
if (items.isNotEmpty()) data.add(android.view.KeyboardShortcutGroup(group.heading, items))
if (items.isNotEmpty()) data.add(android.view.KeyboardShortcutGroup(tr(group.heading), items))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SaveToDeviceActivity : ComponentActivity() {
files.isEmpty() -> {
// (gone from the cache since they were shared): said, not a window that closes on nothing
AppLog.w("ProCraft", "none of the ${asked.size} files to save to the device is there any more")
Toast.makeText(applicationContext, "Couldn't save the file", Toast.LENGTH_LONG).show()
Toast.makeText(applicationContext, tr("Couldn't save the file"), Toast.LENGTH_LONG).show()
finish()
}
files.size == 1 -> saveOne.launch(
Expand All @@ -77,7 +77,7 @@ class SaveToDeviceActivity : ComponentActivity() {
if (missing > 0) AppLog.w("ProCraft", "$missing of the ${asked.size} files to save to the device weren't there any more")
if (!saved) {
AppLog.w("ProCraft", "${paths.joinToString { it.name }} ($type) wasn't saved to the device")
android.os.Handler(android.os.Looper.getMainLooper()).post { Toast.makeText(app, "Couldn't save the file", Toast.LENGTH_LONG).show() }
android.os.Handler(android.os.Looper.getMainLooper()).post { Toast.makeText(app, tr("Couldn't save the file"), Toast.LENGTH_LONG).show() }
}
}
finish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SaveToGalleryActivity : ComponentActivity() {
if (granted) {
save()
} else {
Toast.makeText(applicationContext, "Couldn't save to Gallery without storage access", Toast.LENGTH_LONG).show()
Toast.makeText(applicationContext, tr("Couldn't save to Gallery without storage access"), Toast.LENGTH_LONG).show()
finish()
}
}
Expand Down Expand Up @@ -156,10 +156,10 @@ class SaveToGalleryActivity : ComponentActivity() {

/** What is said once [saved] of [of] files have gone to the gallery. */
internal fun gallerySavedNote(saved: Int, of: Int): String = when {
saved == of && saved == 1 -> "Saved to Gallery"
saved == of -> "$saved saved to Gallery"
saved == 0 -> "Couldn't save to Gallery"
else -> "Saved $saved of $of to Gallery"
saved == of && saved == 1 -> tr("Saved to Gallery")
saved == of -> tr("{0} saved to Gallery", saved)
saved == 0 -> tr("Couldn't save to Gallery")
else -> tr("Saved {0} of {1} to Gallery", saved, of)
}

/** Whether files of type [mime] can go to the gallery: the pictures and videos gallery apps show. */
Expand Down
Loading
Loading