diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..7b4c10c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,22 @@ +version: 2 +updates: + - package-ecosystem: "gradle" + directory: "/" + schedule: + interval: "weekly" + open-pull-requests-limit: 5 + groups: + gradle-plugin-deps: + patterns: + - "*" + + - package-ecosystem: "gradle" + directory: "/example" + schedule: + interval: "weekly" + open-pull-requests-limit: 5 + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 420f726..bb184dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,11 +18,11 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v4 with: distribution: temurin - java-version: '17' + java-version: '21' - name: Validate Gradle wrapper uses: gradle/actions/wrapper-validation@v4 @@ -30,11 +30,8 @@ jobs: - name: Set up Gradle uses: gradle/actions/setup-gradle@v4 - - name: Compile - run: ./gradlew compileKotlin compileTestKotlin --stacktrace - - - name: Test - run: ./gradlew test --stacktrace + - name: Check (compile + test + 추후 lint) + run: ./gradlew check --stacktrace - name: Upload test report if: failure() @@ -43,3 +40,123 @@ jobs: name: test-report path: build/reports/tests/test retention-days: 7 + + example: + name: Example App Build + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '21' + + - name: Set up Android SDK + uses: android-actions/setup-android@v3 + + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Verify plugin tasks registered + working-directory: example + run: | + ./gradlew :app:tasks --group androidStringTable | tee tasks.txt + grep -qw downloadSpreadsheet tasks.txt + grep -qw generateStringsXmls tasks.txt + grep -qw updateResource tasks.txt + + - name: Lint example app + working-directory: example + run: ./gradlew :app:lintDebug --stacktrace + + - name: Build example app (composite build of plugin) + working-directory: example + run: ./gradlew :app:assembleDebug --stacktrace + + - name: Upload example APK + if: success() + uses: actions/upload-artifact@v4 + with: + name: example-app-debug + path: example/app/build/outputs/apk/debug/*.apk + retention-days: 7 + + - name: Upload lint report + if: always() + uses: actions/upload-artifact@v4 + with: + name: example-lint-report + path: example/app/build/reports/lint-results-*.html + retention-days: 7 + + e2e: + name: Plugin E2E (Google Drive) + runs-on: ubuntu-latest + needs: example + # forks can't access secrets; skip for cross-repo PRs + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Determine credentials presence + id: creds + env: + HAS_CREDS: ${{ secrets.GDRIVE_CREDENTIALS_JSON != '' && secrets.GDRIVE_TOKENS_TAR_B64 != '' }} + run: echo "has=$HAS_CREDS" >> "$GITHUB_OUTPUT" + + - name: Skip notice + if: steps.creds.outputs.has != 'true' + run: echo "::notice::GDRIVE_CREDENTIALS_JSON / GDRIVE_TOKENS_TAR_B64 secret 미설정 — E2E 스킵" + + - name: Set up JDK 21 + if: steps.creds.outputs.has == 'true' + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '21' + + - name: Set up Android SDK + if: steps.creds.outputs.has == 'true' + uses: android-actions/setup-android@v3 + + - name: Set up Gradle + if: steps.creds.outputs.has == 'true' + uses: gradle/actions/setup-gradle@v4 + + - name: Restore credentials + if: steps.creds.outputs.has == 'true' + working-directory: example/app/i18n + env: + GDRIVE_CREDENTIALS_JSON: ${{ secrets.GDRIVE_CREDENTIALS_JSON }} + GDRIVE_TOKENS_TAR_B64: ${{ secrets.GDRIVE_TOKENS_TAR_B64 }} + run: | + printf '%s' "$GDRIVE_CREDENTIALS_JSON" > credentials.json + echo "$GDRIVE_TOKENS_TAR_B64" | base64 -d | tar xz + test -d drive_all_tokens + + - name: Run plugin E2E (:app:updateResource) + if: steps.creds.outputs.has == 'true' + working-directory: example + run: ./gradlew :app:updateResource --stacktrace + + - name: Verify generated XML + if: steps.creds.outputs.has == 'true' + working-directory: example/app/src/main/res + run: | + test -f values/strings_generated.xml + test -s values/strings_generated.xml + python3 -c "import xml.etree.ElementTree as ET; ET.parse('values/strings_generated.xml')" + variants=$(ls -d values-* 2>/dev/null | wc -l | tr -d ' ') + echo "locale variants found: $variants" + test "$variants" -ge 1 + + - name: Cleanup credentials + if: always() && steps.creds.outputs.has == 'true' + working-directory: example/app/i18n + run: | + rm -f credentials.json + rm -rf drive_all_tokens diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..0b17482 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,49 @@ +name: CodeQL + +on: + push: + branches: [main] + pull_request: + branches: [main] + schedule: + - cron: "0 3 * * 1" + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + analyze: + name: Analyze (Java/Kotlin) + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '21' + + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: java-kotlin + + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Autobuild + uses: github/codeql-action/autobuild@v3 + env: + _JAVA_OPTIONS: "-Xmx5g" + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:java-kotlin" diff --git a/README.md b/README.md index 5c23275..4ddc927 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,36 @@ [![](https://jitpack.io/v/rsupportrnd/android-string-table.svg)](https://jitpack.io/#rsupportrnd/android-string-table) # android-string-table -## 💡 소개 +## 💡 Overview *** -구글 스프레드 시트에 작성한 내용을 안드로이드 스튜디오에서 사용 가능한 문자열 리소스 파일(.xml)로 변환한다. +Converts a Google Spreadsheet into Android string resource files (`strings_generated.xml`) that Android Studio can consume directly. -## 💡 Package별 기능 상세 +## 💡 Requirements *** -### com.rsupport.download -구글 시트를 엑설 파일(.xlsx)로 다운로드 한다. +- **JDK 21 or higher** — Android Studio Ladybug (2024.2.1) and newer ship JDK 21 by default. Older IDEs must be upgraded or pointed at a JDK 21 runtime. +- **Gradle 8.10+** (wrapper) +- **Android Gradle Plugin 8.0+** -### com.rsupport.google -구글 api 관련 패키지 +## 💡 Package structure +*** +### `com.rsupport.download` +Downloads a Google Sheet as an Excel file (`.xlsx`). + +### `com.rsupport.google` +Google API wrappers (Drive / Sheets / OAuth). -### com.ruspport.stringtable -다운로드 한 엑셀 파일을 이용하여 문자열 리소스 파일을 생성한다. +### `com.rsupport.stringtable` +Generates string resource files from the downloaded Excel file. -### com.rsupport.plugin -플러그인 관련 패키지 +### `com.rsupport.plugin` +Gradle plugin wiring — exposes the `androidStringTable { ... }` extension and registers the tasks below. -## 💡플러그인 적용 방법 +## 💡 Applying the plugin *** -### Kotlin DSL (Version catalog) +### Kotlin DSL (with Version catalog) -### Build.gradle.kts(:project) -````kotlin +#### `build.gradle.kts` (project) +```kotlin buildscript { repositories { maven("https://jitpack.io") @@ -33,42 +39,42 @@ buildscript { classpath(libs.rsupportrnd.android.string.table) } } -```` +``` -### libs.versions.toml -````toml +#### `libs.versions.toml` +```toml [versions] -androidStringTable = "1.1.0" +androidStringTable = "1.2.0" [libraries] rsupportrnd-android-string-table = { group = "com.github.rsupportrnd", name = "android-string-table", version.ref = "androidStringTable" } [plugins] android-string-table = { id = "android-string-table" } -```` +``` -### Build.gradle.kts(:app) -````kotlin +#### `build.gradle.kts` (app) +```kotlin plugins { alias(libs.plugins.android.string.table) } androidStringTable { - googleDriveCredentialPath.value("${project.rootDir}/strings/credentials.json") - targetSheetUrl.value("https://docs.google.com/spreadsheets/d/1W6WG_b40FmvyVbstodPgwA6USc0PRANoemCMN66_peM/edit#gid=0") // full url of sheet included tab gid - outputXlsxFilePath.value("${project.rootDir}/strings/archive.xlsx") - androidResourcePath.value("$projectDir/src/main/res") - - // 아래부터 생략 가능 - rowPositionColumnHeader.value(1) - defaultLanguageForValues.value("en") // values 로 지정됨 - doNotConvertNewLine.value(false) - outputXmlFileName.value("strings_generated") + googleDriveCredentialPath.set("${project.rootDir}/strings/credentials.json") + targetSheetUrl.set("https://docs.google.com/spreadsheets/d/1W6WG_b40FmvyVbstodPgwA6USc0PRANoemCMN66_peM/edit#gid=0") // full sheet URL including the tab gid + outputXlsxFilePath.set("${project.rootDir}/strings/archive.xlsx") + androidResourcePath.set("$projectDir/src/main/res") + + // optional below + rowPositionColumnHeader.set(1) + defaultLanguageForValues.set("en") // this language's column is written to `values/` instead of `values-en/` + doNotConvertNewLine.set(false) + outputXmlFileName.set("strings_generated") } -```` +``` -### Setting.gradle.kts(:Project Settings) -````kotlin +#### `settings.gradle.kts` (project settings) +```kotlin dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { @@ -77,79 +83,79 @@ dependencyResolutionManagement { maven("https://jitpack.io") } } -```` +``` *** ### Groovy DSL -### Build.gradle(:project) -````groovy -buildscript { - repositories { - google() - jcenter() - maven { url 'https://jitpack.io' } - } - dependencies { - classpath 'com.github.rsupportrnd:android-string-table:1.1.0' - } +#### `build.gradle` (project) +```groovy +buildscript { + repositories { + google() + mavenCentral() + maven { url 'https://jitpack.io' } } -```` -### Build.gradle(:app) -````groovy + dependencies { + classpath 'com.github.rsupportrnd:android-string-table:1.2.0' + } +} +``` +#### `build.gradle` (app) +```groovy apply plugin: 'android-string-table' - -androidStringTable { + +androidStringTable { googleDriveCredentialPath "${project.rootDir}/strings/credentials.json" - targetSheetUrl 'https://docs.google.com/spreadsheets/d/1W6WG_b40FmvyVbstodPgwA6USc0PRANoemCMN66_peM/edit#gid=0' // full url of sheet included tab gid + targetSheetUrl 'https://docs.google.com/spreadsheets/d/1W6WG_b40FmvyVbstodPgwA6USc0PRANoemCMN66_peM/edit#gid=0' // full sheet URL including the tab gid outputXlsxFilePath "${project.rootDir}/strings/archive.xlsx" androidResourcePath "src/main/res" - - // 아래부터 생략 가능 + + // optional below rowPositionColumnHeader 1 - defaultLanguageForValues "en" // values 로 지정됨 + defaultLanguageForValues "en" // this language's column is written to `values/` instead of `values-en/` doNotConvertNewLine false outputXmlFileName "strings_generated.xml" } -```` +``` + +## 💡 Getting the Google credential file +[Guide to obtaining a Google credential](guide-google-credential.md) -## 💡 Credential 파일 다운로드 방법 -[Guide to get google credential](guide-google-credential.md) - -## 💡 플러그인 적용시 생성되는 task +## 💡 Tasks registered by the plugin *** ![screenshot10](screenshots/screenshot_10.png) - **updateResource** - - 스프레드 시트를 다운로드하고 문자열 리소스 파일(.xml)을 생성한다. + + Downloads the spreadsheet and generates string resource files (`.xml`). - **downloadSpreadsheet** - 스프레드 시트를 다운로드 한다. + Downloads the spreadsheet only. - **generateStringsXmls** - 문자열 리소스 파일(.xml)을 생성한다. + Generates string resource files from the already-downloaded spreadsheet. -## 💡 플러그인 적용 가능한 스프레드 시트 작성 방법 +## 💡 Spreadsheet authoring rules *** -➰예제 스프레드 시트 : https://docs.google.com/spreadsheets/d/1W6WG_b40FmvyVbstodPgwA6USc0PRANoemCMN66_peM/edit#gid=0 +➰ Example spreadsheet: https://docs.google.com/spreadsheets/d/1W6WG_b40FmvyVbstodPgwA6USc0PRANoemCMN66_peM/edit#gid=0 ![screenshot11](screenshots/screenshot_11.png) -1. 인덱스 행을 표시하기 위해 "id" 혹은 "identification"을 포함한 문자열을 입력한다. -2. 인덱스 행의 셀 내부 문자열에 "values"를 포함하지 않거나 언어코드가 아닌 열은 파싱되지 않고 넘어간다. -3. 안드로이드 스튜디오에서 국가와 언어 별로 string.xml 파일이 담긴 values 폴더를 명명하는 법칙과 동일하게 "values-국가, 언어 코드"로 해당 열의 국가와 언어를 표기한다. -4. 국가와 언어 코드가 표기되지 않은 단순 "values" 열은 기본 문자열 파일로 변환된다. (default 코드를 지정하면 values 로 치환된다.) +1. To mark the index (header) row, enter a string that contains `id` or `identification` in the first column. +2. In the index row, any column whose header does not contain `values` and is not a valid language code is skipped. +3. Name each locale column with the same qualifier convention Android uses for `values-*` folders (`values-`, e.g. `values-ko`, `values-ja`). +4. A plain `values` column (no language suffix) becomes the default strings file. If `defaultLanguageForValues` is set, the matching column is written to `values/` instead of `values-/`. -## 💡 스프레드 시트 URL +## 💡 Spreadsheet URL *** -공유 기능으로 링크 복사를 하는 것이 아니고 주소창에 있는 주소를 직접 복사해서 붙여넣는다. +Copy the URL directly from the browser address bar — do **not** use the Share → Copy Link option, which produces a different URL shape the plugin cannot parse. The MIT License (MIT) ===================== -Copyright © 2024 RSUPPORT +Copyright © 2026 RSUPPORT Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation -files (the “Software”), to deal in the Software without +files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the @@ -159,7 +165,7 @@ conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT @@ -167,4 +173,3 @@ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - diff --git a/build.gradle.kts b/build.gradle.kts index 69230b2..06a6a7a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,25 +1,27 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { `java-gradle-plugin` - kotlin("jvm") version "1.9.0" + kotlin("jvm") version "2.0.21" } group = "com.rsupport" -version = "1.1.0.14" +version = "1.2.0" repositories { mavenCentral() } +kotlin { + jvmToolchain(21) +} + dependencies { testImplementation("junit:junit:4.12") testImplementation("org.hamcrest:hamcrest-library:1.3") testImplementation("org.hamcrest:hamcrest-core:1.3") - api("org.apache.poi:poi:5.4.1") - api("commons-codec:commons-codec:1.5") - api("org.apache.poi:poi-ooxml:5.4.1") + // POI 5.2.5 is the last version aligned with commons-io 2.15.1, which Gradle bundles + // on its core classloader; newer POI triggers NoSuchMethodError on BoundedInputStream.builder() + api("org.apache.poi:poi:5.2.5") + api("org.apache.poi:poi-ooxml:5.2.5") api("org.apache.xmlbeans:xmlbeans:2.3.0") api("stax:stax-api:1.0.1") api("dom4j:dom4j:1.6.1") @@ -43,9 +45,3 @@ gradlePlugin { } } } - -tasks.withType().configureEach { - compilerOptions { - jvmTarget.set(JvmTarget.JVM_17) - } -} diff --git a/example/.gitignore b/example/.gitignore index 06358d7..ccc23c8 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -13,4 +13,5 @@ .externalNativeBuild .cxx local.properties -drive_all_tokens/ \ No newline at end of file +drive_all_tokens/ +app/i18n/credentials.json \ No newline at end of file diff --git a/example/app/build.gradle.kts b/example/app/build.gradle.kts index 6dd850f..587871a 100644 --- a/example/app/build.gradle.kts +++ b/example/app/build.gradle.kts @@ -1,18 +1,17 @@ -import com.rsupport.plugin.StringTableExtension - plugins { id("com.android.application") - id("kotlin-android") + id("org.jetbrains.kotlin.android") + id("android-string-table") } android { - compileSdk = 33 - buildToolsVersion = "30.0.3" + namespace = "example.app" + compileSdk = 36 defaultConfig { applicationId = "example.app" - minSdk = 16 - targetSdk = 33 + minSdk = 21 + targetSdk = 36 versionCode = 1 versionName = "1.0" @@ -29,28 +28,37 @@ android { } } compileOptions { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 } kotlinOptions { - jvmTarget = "17" + jvmTarget = "21" + } + lint { + // example app is a plugin demo, not a production app; suppress checks that + // don't reflect plugin quality or are managed elsewhere + disable += setOf( + "MissingTranslation", // example xlsx intentionally has partial locale coverage + "OldTargetApi", // targetSdk bumps tracked separately + "GradleDependency", // Dependabot handles AndroidX version currency + "ObsoleteSdkInt", // not actionable in example app + "UnusedResources", // example only consumes a subset of generated strings + "MonochromeLauncherIcon", // out of scope for plugin demo + ) } } dependencies { - val kotlinVersion = rootProject.extra["kotlin_version"] as String - implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") - implementation("androidx.core:core-ktx:1.3.2") - implementation("androidx.appcompat:appcompat:1.2.0") - implementation("com.google.android.material:material:1.3.0") - implementation("androidx.constraintlayout:constraintlayout:2.0.4") - testImplementation("junit:junit:4.+") - androidTestImplementation("androidx.test.ext:junit:1.1.2") - androidTestImplementation("androidx.test.espresso:espresso-core:3.3.0") + implementation("androidx.core:core-ktx:1.13.1") + implementation("androidx.appcompat:appcompat:1.7.0") + implementation("com.google.android.material:material:1.12.0") + implementation("androidx.constraintlayout:constraintlayout:2.1.4") + testImplementation("junit:junit:4.13.2") + androidTestImplementation("androidx.test.ext:junit:1.2.1") + androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1") } -apply(plugin = "android-string-table") -configure { +androidStringTable { googleDriveCredentialPath.set("${project.rootDir}/app/i18n/credentials.json") targetSheetUrl.set("https://docs.google.com/spreadsheets/d/12hmQ7U0npYM4hK4ck3qN9bMUDRu-ZcPueluxz5X4w30/edit#gid=1661361434") outputXlsxFilePath.set("${project.rootDir}/app/i18n/languages.xlsx") diff --git a/example/app/src/main/AndroidManifest.xml b/example/app/src/main/AndroidManifest.xml index 18213c9..d6932de 100644 --- a/example/app/src/main/AndroidManifest.xml +++ b/example/app/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - + - + diff --git a/example/build.gradle.kts b/example/build.gradle.kts index fe13a26..2137265 100644 --- a/example/build.gradle.kts +++ b/example/build.gradle.kts @@ -1,22 +1,6 @@ -buildscript { - extra["kotlin_version"] = "1.7.10" - repositories { - google() - mavenCentral() - maven(url = "https://jitpack.io") - } - dependencies { - classpath("com.android.tools.build:gradle:7.3.1") - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${extra["kotlin_version"]}") - classpath("com.github.rsupportrnd:android-string-table:1.1.0") - } -} - -allprojects { - repositories { - google() - mavenCentral() - } +plugins { + id("com.android.application") version "8.6.1" apply false + id("org.jetbrains.kotlin.android") version "2.0.21" apply false } tasks.register("clean") { diff --git a/example/gradle/wrapper/gradle-wrapper.properties b/example/gradle/wrapper/gradle-wrapper.properties index 66d996c..367c80d 100644 --- a/example/gradle/wrapper/gradle-wrapper.properties +++ b/example/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip diff --git a/example/settings.gradle.kts b/example/settings.gradle.kts index 721a73e..a21f296 100644 --- a/example/settings.gradle.kts +++ b/example/settings.gradle.kts @@ -1,2 +1,19 @@ +pluginManagement { + includeBuild("..") + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} + +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} + include(":app") rootProject.name = "StringTableExampleApp" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 394925b..83d2c68 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Thu Mar 13 13:48:22 KST 2025 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/guide-google-credential.md b/guide-google-credential.md index 03ee984..76fd001 100644 --- a/guide-google-credential.md +++ b/guide-google-credential.md @@ -1,40 +1,40 @@ -## 💡 Credential 파일 다운로드 방법 +## 💡 How to obtain the Google credential file *** -**1. 구글 클라우드 콘솔(https://console.cloud.google.com/) 접속 후 로그인** +**1. Open the Google Cloud Console (https://console.cloud.google.com/) and sign in.** -**2. 프로젝트 생성 혹은 프로젝트 선택** +**2. Create a new project or select an existing one.** -**3. "API 및 서비스" 메뉴에서 "라이브러리" 선택** +**3. In the "APIs & Services" menu, open "Library".** ![screenshot1](screenshots/screenshot_1.png) -**4. Google Sheet API, Google Drive API 검색하여 사용 설정** +**4. Search for and enable both the Google Sheets API and the Google Drive API.** ![screenshot2](screenshots/screenshot_2.png) ![screenshot3](screenshots/screenshot_3.png) -**5. "사용자 인증 정보"에서 "사용자 인증 정보 만들기" 클릭 후 "OAuth 클라이언트 ID" 선택** +**5. Under "Credentials", click "Create Credentials" and choose "OAuth client ID".** ![screenshot4](screenshots/screenshot_4.png) -**6. "동의화면 구성" 버튼 클릭** +**6. Click the "Configure consent screen" button.** ![screenshot5](screenshots/screenshot_5.png) -**7. 프로젝트의 목적에 맞게 동의화면 구성** +**7. Configure the consent screen to match your project.** ![screenshot6](screenshots/screenshot_6.png) -**8. "OAuth 클라이언트 ID" 생성 다시 시작** +**8. Return to creating the OAuth client ID.** ![screenshot7](screenshots/screenshot_7.png) -**9. 어플리케이션 유형을 "데스크톱 앱"으로 설정. 이름을 설정 후 "만들기" 버튼 클릭** +**9. Set Application type to "Desktop app", give it a name, then click "Create".** ![screenshot8](screenshots/screenshot_8.png) -**10. OAuth 2.0 클라이언트 ID 목록에서 다운로드 버튼을 클릭하면 client_secret_XXX.json 파일이 다운로드 되는데, 이 json 파일이 credential 파일이다.** +**10. From the OAuth 2.0 Client IDs list, click the download button; a `client_secret_XXX.json` file is downloaded. That JSON file is your credential.** ![screenshot9](screenshots/screenshot_9.png) diff --git a/settings.gradle.kts b/settings.gradle.kts index 6ada047..f6b1fb7 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1 +1,5 @@ +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" +} + rootProject.name = "android-string-table" diff --git a/src/main/java/com/rsupport/google/GoogleCredentials.kt b/src/main/java/com/rsupport/google/GoogleCredentials.kt index 44349ba..06f2ee0 100644 --- a/src/main/java/com/rsupport/google/GoogleCredentials.kt +++ b/src/main/java/com/rsupport/google/GoogleCredentials.kt @@ -17,15 +17,20 @@ import com.google.api.services.drive.DriveScopes object GoogleCredentials { private val JSON_FACTORY: JsonFactory = JacksonFactory.getDefaultInstance() - private const val TOKENS_DIRECTORY_PATH = "drive_all_tokens" + private const val TOKENS_DIRECTORY_NAME = "drive_all_tokens" private val SCOPES = listOf(DriveScopes.DRIVE, SheetsScopes.DRIVE_READONLY) private val HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport() fun createCredentials(credentialFilePath: String): Credential { if(credentialFilePath.isEmpty()) throw IllegalStateException("Credential File Path is Empty.") - val clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, InputStreamReader(FileInputStream(credentialFilePath))) + val credentialFile = File(credentialFilePath) + // Store tokens next to credentials.json so the path is stable across Gradle + // daemon restarts and runner environments (relative paths resolve against the + // daemon JVM CWD, which varies by Gradle version). + val tokensDir = File(credentialFile.parentFile ?: File("."), TOKENS_DIRECTORY_NAME) + val clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, InputStreamReader(FileInputStream(credentialFile))) val flow = GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES) - .setDataStoreFactory(FileDataStoreFactory(File(TOKENS_DIRECTORY_PATH))) + .setDataStoreFactory(FileDataStoreFactory(tokensDir)) .setAccessType("offline") .build() val receiver = LocalServerReceiver.Builder().setPort(8888).build() diff --git a/src/main/java/com/rsupport/stringtable/LanguageCode.kt b/src/main/java/com/rsupport/stringtable/LanguageCode.kt index d447ae6..553fd5c 100644 --- a/src/main/java/com/rsupport/stringtable/LanguageCode.kt +++ b/src/main/java/com/rsupport/stringtable/LanguageCode.kt @@ -21,6 +21,18 @@ class LanguageCode { val code = languageCode.removePrefix("values-") return code.ifBlank { null } } + + // Android resource qualifier expects "-r" for the region segment; a plain hyphen + // ("zh-CN") is rejected by the resource merger at assembleDebug time. Normalize common + // BCP 47-style codes to the Android form; pass through already-qualified codes and + // language-only codes unchanged. + fun toAndroidQualifier(code: String): String { + val parts = code.split("-") + if (parts.size < 2) return code + if (parts.size == 2 && parts[1].length == 3 && parts[1].startsWith("r")) return code + if (parts.size == 2 && parts[1].length == 2) return "${parts[0]}-r${parts[1]}" + return code + } } diff --git a/src/main/java/com/rsupport/stringtable/Sheet2Strings.kt b/src/main/java/com/rsupport/stringtable/Sheet2Strings.kt index f6651bb..956ccd1 100644 --- a/src/main/java/com/rsupport/stringtable/Sheet2Strings.kt +++ b/src/main/java/com/rsupport/stringtable/Sheet2Strings.kt @@ -78,17 +78,16 @@ object Sheet2Strings { defaultLanguage: String, ): String? { if (columnHeader.startsWith("values")) { - if (defaultLanguage == LanguageCode.getActualCode(columnHeader)) { - return "values" - } - return columnHeader + val code = LanguageCode.getActualCode(columnHeader) ?: return "values" + if (defaultLanguage == code) return "values" + return "values-${LanguageCode.toAndroidQualifier(code)}" } if (LanguageCode.isValid(columnHeader)) { if (defaultLanguage == columnHeader) { return "values" } - return "values-$columnHeader" + return "values-${LanguageCode.toAndroidQualifier(columnHeader)}" } return null diff --git a/src/test/java/LanguageCodeTest.kt b/src/test/java/LanguageCodeTest.kt index 7a36ebd..d9cd3de 100644 --- a/src/test/java/LanguageCodeTest.kt +++ b/src/test/java/LanguageCodeTest.kt @@ -2,6 +2,7 @@ import com.rsupport.stringtable.LanguageCode import org.junit.Test import org.junit.Assert.assertTrue import org.junit.Assert.assertFalse +import org.junit.Assert.assertEquals import java.util.* class LanguageCodeTest { @@ -49,4 +50,23 @@ class LanguageCodeTest { ) } } + + @Test + fun testToAndroidQualifier() { + val cases = mapOf( + "zh-CN" to "zh-rCN", + "zh-TW" to "zh-rTW", + "en-US" to "en-rUS", + "ko-KR" to "ko-rKR", + // already in Android form — pass through + "zh-rCN" to "zh-rCN", + "zh-rTW" to "zh-rTW", + // language only — no change + "ko" to "ko", + "en" to "en", + ) + for ((input, expected) in cases) { + assertEquals("toAndroidQualifier($input)", expected, LanguageCode.toAndroidQualifier(input)) + } + } } \ No newline at end of file diff --git a/tool/readme.md b/tool/readme.md index 562341d..6bcfd23 100644 --- a/tool/readme.md +++ b/tool/readme.md @@ -2,18 +2,18 @@ ## merge.py -선택된 폴더에서 선택된 동일 이름 xml파일들을 하나로 합칩니다. +Merges same-named XML files found under the given folder into a single output file. -### res 폴더 내 모든 strings.xml을 합치는 경우 +### Merge every `strings.xml` under a `res/` directory `python merge.py input [res path]` or `python merge.py input [res path] target "strings.xml" output "merged_strings.xlsx"` -### res 폴더 내 모든 strings.xml strings_generated.xml을 합치는 경우 +### Merge every `strings.xml` and `strings_generated.xml` under a `res/` directory -#### 중복 id 시, strings_generated.xml을 우선 +#### On duplicate ids, prefer `strings_generated.xml` `python merge.py input [res path] target "strings.xml" target "strings_generated.xml" output "merged_strings.xlsx"` -#### 중복 id 시 strings.xml을 우선 +#### On duplicate ids, prefer `strings.xml` `python merge.py input [res path] target "strings_generated.xml" target "strings.xml" output "merged_strings.xlsx"`