Skip to content

docs(cndocs): 同步多篇 React Native 中文文档更新#1008

Merged
sunnylqm merged 5 commits intoproductionfrom
auto-translate-20260410-batch
Apr 10, 2026
Merged

docs(cndocs): 同步多篇 React Native 中文文档更新#1008
sunnylqm merged 5 commits intoproductionfrom
auto-translate-20260410-batch

Conversation

@sunnylqm
Copy link
Copy Markdown

@sunnylqm sunnylqm commented Apr 10, 2026

Summary

  • 补齐 AccessibilityInfo 缺失的最新 API 文档内容
  • 同步 DevSettings、Dimensions 与 _remove-global-cli 的上游更新
  • 对齐新版 admonition、方法签名与示例代码结构

Updated files

  • cndocs/accessibilityinfo.md
  • cndocs/devsettings.md
  • cndocs/dimensions.md
  • cndocs/_remove-global-cli.md

Notes

  • sync-translations.sh 在改动合入 production 前,仍可能继续将这些文件列为候选,这是基于 production 分支时间戳的当前脚本行为。

Test Plan

  • 逐文件对照英文源文档检查结构与内容
  • 确认仅提交文档同步改动
  • 本地检查 git diff 与提交内容

Summary by CodeRabbit

  • New Features

    • Added new accessibility APIs for detecting high text contrast and system color settings, plus a method for triggering accessibility events on Android and iOS.
  • Documentation

    • Improved documentation clarity across accessibility, development settings, and dimensions modules with enhanced type information and practical examples.
  • Chores

    • Enhanced translation synchronization tooling with new reporting capabilities.

@netlify
Copy link
Copy Markdown

netlify bot commented Apr 10, 2026

Deploy Preview for reactnativecn failed. Why did it fail? →

Name Link
🔨 Latest commit b52b281
🔍 Latest deploy log https://app.netlify.com/projects/reactnativecn/deploys/69d8e6e1a0d9b500088a5c6d

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 10, 2026

📝 Walkthrough

Walkthrough

The PR updates Chinese React Native documentation with improved API signatures and deprecation notices for AccessibilityInfo and DevSettings. Multiple documentation files are refactored with modern callout blocks, updated code examples, and local asset references. Additionally, a translation synchronization script and npm task are introduced to automate documentation sync workflows.

Changes

Cohort / File(s) Summary
API Documentation Updates
cndocs/accessibilityinfo.md, cndocs/devsettings.md
Added new AccessibilityInfo methods (isHighTextContrastEnabled(), isDarkerSystemColorsEnabled(), sendAccessibilityEvent()) with deprecation callout for setAccessibilityFocus(). Updated DevSettings method signatures with explicit type annotations for addMenuItem() and reload(reason?) parameters.
Documentation Refactoring & Examples
cndocs/_remove-global-cli.md, cndocs/dimensions.md, cndocs/turbo-native-modules-ios.md
Converted plain text sections to fenced admonition blocks (warning/info/note). Modernized example code from JSX to TSX, wrapped with SafeAreaProvider/SafeAreaView. Updated iOS TurboModule guide to use generated NativeLocalStorageSpec and added moduleName method; converted external video URLs to local asset paths; added codegenConfig.ios.modulesProvider registration instructions.
Translation Sync Automation
package.json, scripts/sync-translations.sh
Added sync-translations npm script. Consolidated translation candidate selection logic into single pipeline; added --report mode for status reporting of upstream vs. production timestamps; removed redundant diffing strategies.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 Docs dance in callout blocks so bright,
New APIs sparkle, TypeScript tight,
Translations sync with scripts so keen,
The cleanest docs you've ever seen! 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 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 objective: syncing updates to multiple Chinese React Native documentation files (AccessibilityInfo, DevSettings, Dimensions, _remove-global-cli) with upstream changes.

✏️ 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 auto-translate-20260410-batch

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

@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: 5

🧹 Nitpick comments (1)
cndocs/_remove-global-cli.md (1)

2-2: Consider mentioning both packages in the warning text.

The warning text mentions the react-native-cli package, but the command removes both react-native-cli and @react-native-community/cli. While the command is correct, explicitly mentioning both packages in the warning text would improve clarity and help users understand why both are being removed.

📝 Optional refinement for clarity
-如果你之前全局安装过 `react-native-cli` 包,请将其移除,因为它可能会导致一些意外问题:
+如果你之前全局安装过 `react-native-cli` 或 `@react-native-community/cli` 包,请将其移除,因为它们可能会导致一些意外问题:

Also applies to: 5-5

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cndocs/_remove-global-cli.md` at line 2, Update the warning sentence that
currently only names "react-native-cli" so it explicitly mentions both
"react-native-cli" and "@react-native-community/cli" to match the uninstall
command; locate the sentence containing the string "react-native-cli" in the
document and rewrite it to mention both package names (and mirror this change in
the other occurrence noted by "Also applies to: 5-5").
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cndocs/accessibilityinfo.md`:
- Around line 230-242: Add missing semicolons to the TypeScript method
signatures: terminate the declarations for static isHighTextContrastEnabled():
Promise<boolean> and static isDarkerSystemColorsEnabled(): Promise<boolean> with
a trailing semicolon to match the rest of the file's signature style and restore
consistency.
- Around line 280-282: The method signature for sendAccessibilityEvent is
missing an explicit return type; update the declaration of
sendAccessibilityEvent(host: HostInstance, eventType: AccessibilityEventTypes)
to include an explicit void return annotation (i.e., append : void) to match
other void-returning methods like announceForAccessibility and
setAccessibilityFocus and improve clarity and consistency.

In `@cndocs/dimensions.md`:
- Around line 57-66: The mapped Text nodes rendering
Object.entries(dimensions.window) and Object.entries(dimensions.screen) lack
stable key props causing React warnings; update both map callbacks (the
expressions using Object.entries(dimensions.window).map and
Object.entries(dimensions.screen).map) to add a unique key prop—e.g., use the
entry key (key) or a combined string like `${key}-window` / `${key}-screen`—on
each <Text> element so each rendered list item has a stable React key.

In `@cndocs/turbo-native-modules-ios.md`:
- Around line 155-158: The workspace name in the iOS command snippet is
inconsistent: replace the reference to SampleApp.xcworkspace with
TurboModuleExample.xcworkspace so it matches the earlier step that opens
TurboModuleExample.xcworkspace; update the `open` command in the block so the
snippet uses `TurboModuleExample.xcworkspace` while keeping the preceding
`bundle exec pod install` line unchanged.

In `@scripts/sync-translations.sh`:
- Around line 63-69: The script's git log assignments (e.g., upstream_epoch and
translation_epoch) can be empty even though the command exits 0, so the numeric
comparisons fail; change the capture to explicitly default empty output to 0
(for example: run git log -1 --format="%ct" ... into a variable, then set
variable=${variable:-0}) and apply the same pattern to any other epoch captures
and the date fallback so the subsequent -eq and -gt numeric comparisons work
correctly (update the usages around upstream_epoch, translation_epoch and any
other epoch/date variables in sync-translations.sh).

---

Nitpick comments:
In `@cndocs/_remove-global-cli.md`:
- Line 2: Update the warning sentence that currently only names
"react-native-cli" so it explicitly mentions both "react-native-cli" and
"@react-native-community/cli" to match the uninstall command; locate the
sentence containing the string "react-native-cli" in the document and rewrite it
to mention both package names (and mirror this change in the other occurrence
noted by "Also applies to: 5-5").
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 026b1c61-ad16-4204-a9ef-b68daa2840bd

📥 Commits

Reviewing files that changed from the base of the PR and between eda9403 and b52b281.

📒 Files selected for processing (7)
  • cndocs/_remove-global-cli.md
  • cndocs/accessibilityinfo.md
  • cndocs/devsettings.md
  • cndocs/dimensions.md
  • cndocs/turbo-native-modules-ios.md
  • package.json
  • scripts/sync-translations.sh

Comment on lines +230 to +242
```tsx
static isHighTextContrastEnabled(): Promise<boolean>
```

查询是否启用了高对比度文本。返回 Promise,启用为 `true`,否则为 `false`。

---

### `isDarkerSystemColorsEnabled()` <div className="label ios">iOS</div>

```tsx
static isDarkerSystemColorsEnabled(): Promise<boolean>
```
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, find and read the file to check the lines mentioned
wc -l cndocs/accessibilityinfo.md

Repository: reactnativecn/react-native-website

Length of output: 109


🏁 Script executed:

# Read lines 220-250 to see the context and verify the lines mentioned
sed -n '220,250p' cndocs/accessibilityinfo.md | cat -n

Repository: reactnativecn/react-native-website

Length of output: 888


🏁 Script executed:

# Search for all TypeScript method signatures in the file to check semicolon patterns
rg -n "static.*\(\).*Promise" cndocs/accessibilityinfo.md

Repository: reactnativecn/react-native-website

Length of output: 638


🏁 Script executed:

# More broadly, check all tsx code blocks for TypeScript signatures to understand the pattern
rg -B2 -A2 "^static.*\(\)" cndocs/accessibilityinfo.md

Repository: reactnativecn/react-native-website

Length of output: 757


Add semicolons to the two API method signatures to maintain consistency with the rest of the file.

Lines 231 and 241 are missing semicolons at the end of the TypeScript signatures. All other method signatures in the file (except for a typo on line 171) end with semicolons. This is a style inconsistency that should be fixed.

✏️ Suggested fix
-static isHighTextContrastEnabled(): Promise<boolean>
+static isHighTextContrastEnabled(): Promise<boolean>;
...
-static isDarkerSystemColorsEnabled(): Promise<boolean>
+static isDarkerSystemColorsEnabled(): Promise<boolean>;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cndocs/accessibilityinfo.md` around lines 230 - 242, Add missing semicolons
to the TypeScript method signatures: terminate the declarations for static
isHighTextContrastEnabled(): Promise<boolean> and static
isDarkerSystemColorsEnabled(): Promise<boolean> with a trailing semicolon to
match the rest of the file's signature style and restore consistency.

Comment on lines +280 to +282
```tsx
static sendAccessibilityEvent(host: HostInstance, eventType: AccessibilityEventTypes);
```
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, check if the file exists and read the relevant lines
cat -n cndocs/accessibilityinfo.md | sed -n '275,290p'

Repository: reactnativecn/react-native-website

Length of output: 586


🏁 Script executed:

# Get more context around the file
wc -l cndocs/accessibilityinfo.md

Repository: reactnativecn/react-native-website

Length of output: 109


🏁 Script executed:

# Search for sendAccessibilityEvent in the codebase
rg "sendAccessibilityEvent" --type ts --type tsx -A 3 -B 1

Repository: reactnativecn/react-native-website

Length of output: 105


🏁 Script executed:

# Search for sendAccessibilityEvent in all files
rg "sendAccessibilityEvent" -A 3 -B 1

Repository: reactnativecn/react-native-website

Length of output: 50392


🏁 Script executed:

# Look for TypeScript definition files
fd -e "d.ts" | head -20

Repository: reactnativecn/react-native-website

Length of output: 203


🏁 Script executed:

# Search specifically in type definition or source files
rg "sendAccessibilityEvent" --type typescript -A 3 -B 1

Repository: reactnativecn/react-native-website

Length of output: 112


🏁 Script executed:

# Check English version of docs for comparison
cat -n docs/accessibilityinfo.md | sed -n '275,290p'

Repository: reactnativecn/react-native-website

Length of output: 985


🏁 Script executed:

# Search for AccessibilityInfo interface/type definition
rg "interface AccessibilityInfo|class AccessibilityInfo|type AccessibilityInfo" -A 15

Repository: reactnativecn/react-native-website

Length of output: 60


🏁 Script executed:

# Look for any .d.ts files that might contain type definitions
find . -name "*.d.ts" -type f | head -10

Repository: reactnativecn/react-native-website

Length of output: 209


🏁 Script executed:

# Search for any React Native type definitions or imports in the docs
rg "HostInstance|AccessibilityEventTypes" -A 2 -B 2 | head -50

Repository: reactnativecn/react-native-website

Length of output: 5145


🏁 Script executed:

# Check if there are any actual source files beyond documentation
find . -path ./node_modules -prune -o -name "*.ts" -o -name "*.tsx" | grep -v node_modules | grep -v versioned_docs | head -20

Repository: reactnativecn/react-native-website

Length of output: 854


🏁 Script executed:

# Check if other methods in the same file have return types specified
cat -n cndocs/accessibilityinfo.md | sed -n '200,350p' | grep -E "static|function|\(" | head -20

Repository: reactnativecn/react-native-website

Length of output: 1030


🏁 Script executed:

# Check broader context around sendAccessibilityEvent - look for other method signatures
rg "static \w+\(" cndocs/accessibilityinfo.md -A 1 -B 1

Repository: reactnativecn/react-native-website

Length of output: 1254


Add explicit return type : void to sendAccessibilityEvent signature.

Line 281: The method signature lacks an explicit return type annotation. While other void-returning methods in the same file (announceForAccessibility, setAccessibilityFocus) follow the same pattern, explicitly declaring : void improves clarity and consistency with Promise-returning methods in the documentation.

✏️ Suggested fix
-static sendAccessibilityEvent(host: HostInstance, eventType: AccessibilityEventTypes);
+static sendAccessibilityEvent(
+  host: HostInstance,
+  eventType: AccessibilityEventTypes,
+): void;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
```tsx
static sendAccessibilityEvent(host: HostInstance, eventType: AccessibilityEventTypes);
```
static sendAccessibilityEvent(
host: HostInstance,
eventType: AccessibilityEventTypes,
): void;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cndocs/accessibilityinfo.md` around lines 280 - 282, The method signature for
sendAccessibilityEvent is missing an explicit return type; update the
declaration of sendAccessibilityEvent(host: HostInstance, eventType:
AccessibilityEventTypes) to include an explicit void return annotation (i.e.,
append : void) to match other void-returning methods like
announceForAccessibility and setAccessibilityFocus and improve clarity and
consistency.

Comment thread cndocs/dimensions.md
Comment on lines +57 to +66
{Object.entries(dimensions.window).map(([key, value]) => (
<Text>
{key} - {value}
</Text>
))}
<Text style={styles.header}>Screen Dimensions</Text>
{Object.entries(dimensions.screen).map(([key, value]) => (
<Text>
{key} - {value}
</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.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, check if the file exists and examine its content around lines 57-66
head -70 cndocs/dimensions.md | tail -20

Repository: reactnativecn/react-native-website

Length of output: 621


🏁 Script executed:

# Check the file type and context
head -20 cndocs/dimensions.md

Repository: reactnativecn/react-native-website

Length of output: 450


🏁 Script executed:

# Get the full context around lines 57-66 with line numbers
sed -n '50,75p' cndocs/dimensions.md | cat -n

Repository: reactnativecn/react-native-website

Length of output: 911


Add stable key props to the mapped <Text> nodes.

Both Object.entries(...).map() blocks render lists without keys, which will trigger React warnings. Documentation examples should demonstrate best practices.

Proposed fix
-        {Object.entries(dimensions.window).map(([key, value]) => (
-          <Text>
+        {Object.entries(dimensions.window).map(([key, value]) => (
+          <Text key={`window-${key}`}>
             {key} - {value}
           </Text>
         ))}
         <Text style={styles.header}>Screen Dimensions</Text>
-        {Object.entries(dimensions.screen).map(([key, value]) => (
-          <Text>
+        {Object.entries(dimensions.screen).map(([key, value]) => (
+          <Text key={`screen-${key}`}>
             {key} - {value}
           </Text>
         ))}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{Object.entries(dimensions.window).map(([key, value]) => (
<Text>
{key} - {value}
</Text>
))}
<Text style={styles.header}>Screen Dimensions</Text>
{Object.entries(dimensions.screen).map(([key, value]) => (
<Text>
{key} - {value}
</Text>
{Object.entries(dimensions.window).map(([key, value]) => (
<Text key={`window-${key}`}>
{key} - {value}
</Text>
))}
<Text style={styles.header}>Screen Dimensions</Text>
{Object.entries(dimensions.screen).map(([key, value]) => (
<Text key={`screen-${key}`}>
{key} - {value}
</Text>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cndocs/dimensions.md` around lines 57 - 66, The mapped Text nodes rendering
Object.entries(dimensions.window) and Object.entries(dimensions.screen) lack
stable key props causing React warnings; update both map callbacks (the
expressions using Object.entries(dimensions.window).map and
Object.entries(dimensions.screen).map) to add a unique key prop—e.g., use the
entry key (key) or a combined string like `${key}-window` / `${key}-screen`—on
each <Text> element so each rendered list item has a stable React key.

Comment on lines +155 to +158
```bash
# from the ios folder
bundle exec pod install
open SampleApp.xcworkspace
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Keep the workspace name consistent with the rest of the tutorial.

Earlier steps open TurboModuleExample.xcworkspace at Line 18, but this command switches to SampleApp.xcworkspace. Following the guide verbatim will point readers at the wrong workspace name.

Proposed fix
-open SampleApp.xcworkspace
+open TurboModuleExample.xcworkspace
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cndocs/turbo-native-modules-ios.md` around lines 155 - 158, The workspace
name in the iOS command snippet is inconsistent: replace the reference to
SampleApp.xcworkspace with TurboModuleExample.xcworkspace so it matches the
earlier step that opens TurboModuleExample.xcworkspace; update the `open`
command in the block so the snippet uses `TurboModuleExample.xcworkspace` while
keeping the preceding `bundle exec pod install` line unchanged.

Comment on lines +63 to +69
upstream_epoch=$(git log -1 --format="%ct" upstream/main -- "$source" 2>/dev/null || echo 0)
translation_epoch=$(git log -1 --format="%ct" production -- "$target" 2>/dev/null || echo 0)

# Fallback for translations not yet present on production.
if [ "$translation_epoch" -eq 0 ] 2>/dev/null; then
translation_epoch=$(git log -1 --format="%ct" -- "$target" 2>/dev/null || echo 0)
fi
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# First, let's find and read the script file
find . -name "sync-translations.sh" -type f

Repository: reactnativecn/react-native-website

Length of output: 108


🏁 Script executed:

# Test git log behavior when ref exists but path has no commits
# This tests the core claim of the review comment

python3 << 'EOF'
import subprocess
import tempfile
import os
import shutil

# Create a temporary git repo to test the behavior
tmpdir = tempfile.mkdtemp()
os.chdir(tmpdir)

# Initialize repo with two branches
subprocess.run(['git', 'init'], check=True, capture_output=True)
subprocess.run(['git', 'config', 'user.email', 'test@test.com'], check=True, capture_output=True)
subprocess.run(['git', 'config', 'user.name', 'Test User'], check=True, capture_output=True)

# Create initial commit on main
with open('file.txt', 'w') as f:
    f.write('content')
subprocess.run(['git', 'add', 'file.txt'], check=True, capture_output=True)
subprocess.run(['git', 'commit', '-m', 'initial'], check=True, capture_output=True)

# Create production branch but don't add the target file there
subprocess.run(['git', 'checkout', '-b', 'production'], check=True, capture_output=True)
with open('other.txt', 'w') as f:
    f.write('other')
subprocess.run(['git', 'add', 'other.txt'], check=True, capture_output=True)
subprocess.run(['git', 'commit', '-m', 'production commit'], check=True, capture_output=True)

# Now test git log on a path that doesn't exist on production
result = subprocess.run(
    ['git', 'log', '-1', '--format=%ct', 'production', '--', 'target_file.txt'],
    capture_output=True,
    text=True
)

print(f"Exit code: {result.returncode}")
print(f"Stdout: '{result.stdout}'")
print(f"Stderr: '{result.stderr}'")
print(f"Stdout is empty: {result.stdout == ''}")
print(f"Stdout after strip: '{result.stdout.strip()}'")

os.chdir('/')
shutil.rmtree(tmpdir)
EOF

Repository: reactnativecn/react-native-website

Length of output: 157


🏁 Script executed:

# Test bash behavior with empty variable assignment and -eq comparison
bash << 'EOF'
# Test 1: What happens when command substitution produces empty output?
var=$(echo "")
echo "Test 1 - Empty echo:"
echo "  var='$var'"
echo "  var is unset: $([[ -z $var ]] && echo yes || echo no)"

# Test 2: What does -eq 0 do with empty string?
var=""
echo ""
echo "Test 2 - -eq comparison with empty string:"
if [ "$var" -eq 0 ] 2>/dev/null; then
    echo "  [ \"\$var\" -eq 0 ] returned true"
else
    echo "  [ \"\$var\" -eq 0 ] returned false"
fi

# Test 3: What about unset variable?
unset var
echo ""
echo "Test 3 - -eq comparison with unset variable:"
if [ "$var" -eq 0 ] 2>/dev/null; then
    echo "  [ \"\$var\" -eq 0 ] returned true"
else
    echo "  [ \"\$var\" -eq 0 ] returned false"
fi

# Test 4: Using :- operator
var=""
result=${var:-0}
echo ""
echo "Test 4 - Using :- operator with empty string:"
echo "  \${var:-0} = '$result'"
EOF

Repository: reactnativecn/react-native-website

Length of output: 350


🏁 Script executed:

# Now let's examine the actual script at the problematic lines
if [ -f scripts/sync-translations.sh ]; then
    echo "=== Reading scripts/sync-translations.sh, lines 60-75 ==="
    sed -n '60,75p' scripts/sync-translations.sh
fi

Repository: reactnativecn/react-native-website

Length of output: 939


🏁 Script executed:

# Let's see where the epoch values are used in the script
sed -n '1,100p' scripts/sync-translations.sh | head -100

Repository: reactnativecn/react-native-website

Length of output: 3122


🏁 Script executed:

# Search for where upstream_epoch and translation_epoch are compared
grep -n "upstream_epoch\|translation_epoch" scripts/sync-translations.sh | head -20

Repository: reactnativecn/react-native-website

Length of output: 567


🏁 Script executed:

# Let's look at the full context of how these variables are used
sed -n '63,95p' scripts/sync-translations.sh

Repository: reactnativecn/react-native-website

Length of output: 1429


Fix empty git log output handling to ensure fallback logic executes correctly.

When git log -1 --format="%ct" production -- "$target" finds no commits for a path on the production branch, it returns exit code 0 with empty output. The || echo 0 fallback does not execute because the command succeeds. The empty string then fails the -eq 0 comparison at line 67, silently skipping the intended fallback to the current branch. The same issue affects the -gt comparisons at lines 77 and 85, which treat empty epoch values as false, causing the script to incorrectly classify files as "up to date" when they should be flagged for resync. The date fallback at lines 73–74 is also affected.

Proposed fix
-upstream_epoch=$(git log -1 --format="%ct" upstream/main -- "$source" 2>/dev/null || echo 0)
-translation_epoch=$(git log -1 --format="%ct" production -- "$target" 2>/dev/null || echo 0)
+upstream_epoch=$(git log -1 --format="%ct" upstream/main -- "$source" 2>/dev/null || true)
+upstream_epoch=${upstream_epoch:-0}
+translation_epoch=$(git log -1 --format="%ct" production -- "$target" 2>/dev/null || true)
+translation_epoch=${translation_epoch:-0}
 
-# Fallback for translations not yet present on production.
-if [ "$translation_epoch" -eq 0 ] 2>/dev/null; then
-  translation_epoch=$(git log -1 --format="%ct" -- "$target" 2>/dev/null || echo 0)
+# Fallback for translations not yet present on production.
+if [ "$translation_epoch" -eq 0 ]; then
+  translation_epoch=$(git log -1 --format="%ct" -- "$target" 2>/dev/null || true)
+  translation_epoch=${translation_epoch:-0}
 fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
upstream_epoch=$(git log -1 --format="%ct" upstream/main -- "$source" 2>/dev/null || echo 0)
translation_epoch=$(git log -1 --format="%ct" production -- "$target" 2>/dev/null || echo 0)
# Fallback for translations not yet present on production.
if [ "$translation_epoch" -eq 0 ] 2>/dev/null; then
translation_epoch=$(git log -1 --format="%ct" -- "$target" 2>/dev/null || echo 0)
fi
upstream_epoch=$(git log -1 --format="%ct" upstream/main -- "$source" 2>/dev/null || true)
upstream_epoch=${upstream_epoch:-0}
translation_epoch=$(git log -1 --format="%ct" production -- "$target" 2>/dev/null || true)
translation_epoch=${translation_epoch:-0}
# Fallback for translations not yet present on production.
if [ "$translation_epoch" -eq 0 ]; then
translation_epoch=$(git log -1 --format="%ct" -- "$target" 2>/dev/null || true)
translation_epoch=${translation_epoch:-0}
fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/sync-translations.sh` around lines 63 - 69, The script's git log
assignments (e.g., upstream_epoch and translation_epoch) can be empty even
though the command exits 0, so the numeric comparisons fail; change the capture
to explicitly default empty output to 0 (for example: run git log -1
--format="%ct" ... into a variable, then set variable=${variable:-0}) and apply
the same pattern to any other epoch captures and the date fallback so the
subsequent -eq and -gt numeric comparisons work correctly (update the usages
around upstream_epoch, translation_epoch and any other epoch/date variables in
sync-translations.sh).

@sunnylqm sunnylqm merged commit 769e14c into production Apr 10, 2026
1 of 5 checks passed
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