Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
Xed-Editor/.github/scripts/scan-translations.js at main · Siam11651/Xed-Editor · GitHub
Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Siam11651
Xed-Editor
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
Xed-Editor
/
.github
/
scripts
/
scan-translations.js
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
121 lines (103 loc) · 3.08 KB
main
Breadcrumbs
Xed-Editor
/
.github
/
scripts
/
scan-translations.js
Copy path
Top
File metadata and controls
Code
Blame
121 lines (103 loc) · 3.08 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const
fs
=
require
(
"fs"
)
;
const
path
=
require
(
"path"
)
;
const
{
execSync
}
=
require
(
"child_process"
)
;
const
{
GoogleGenerativeAI
}
=
require
(
"@google/generative-ai"
)
;
const
apiKey
=
process
.
env
.
GEMINI_API_KEY
;
if
(
!
apiKey
)
{
console
.
error
(
"Missing GEMINI_API_KEY environment variable."
)
;
process
.
exit
(
1
)
;
}
const
genAI
=
new
GoogleGenerativeAI
(
apiKey
)
;
// Helper to safely run git commands and get output string
function
runGit
(
command
)
{
try
{
return
execSync
(
command
,
{
encoding
:
"utf8"
}
)
.
trim
(
)
;
}
catch
(
error
)
{
return
""
;
}
}
async
function
main
(
)
{
const
eventName
=
process
.
env
.
GITHUB_EVENT_NAME
;
let
baseDiffTarget
=
""
;
if
(
eventName
===
"pull_request"
)
{
const
baseRef
=
process
.
env
.
GITHUB_BASE_REF
;
runGit
(
`git fetch origin
${
baseRef
}
`
)
;
baseDiffTarget
=
`origin/
${
baseRef
}
...HEAD`
;
}
else
{
let
beforeSha
=
process
.
env
.
GITHUB_BEFORE_SHA
;
const
currentSha
=
process
.
env
.
GITHUB_CURRENT_SHA
;
if
(
!
beforeSha
||
beforeSha
===
"0000000000000000000000000000000000000000"
)
{
beforeSha
=
"HEAD~1"
;
}
baseDiffTarget
=
`
${
beforeSha
}
${
currentSha
}
`
;
}
// 1. Get list of changed files ending with strings.xml
const
rawFiles
=
runGit
(
`git diff --name-only
${
baseDiffTarget
}
`
)
;
if
(
!
rawFiles
)
{
console
.
log
(
"No file changes detected."
)
;
return
;
}
const
files
=
rawFiles
.
split
(
"\n"
)
.
filter
(
file
=>
file
.
endsWith
(
"strings.xml"
)
)
;
if
(
files
.
length
===
0
)
{
console
.
log
(
"No strings.xml changes detected."
)
;
return
;
}
const
model
=
genAI
.
getGenerativeModel
(
{
model
:
"gemini-2.0-flash"
}
)
;
let
workflowFailed
=
false
;
// 2. Loop through each modified strings.xml file and scan its diff
for
(
const
file
of
files
)
{
const
diff
=
runGit
(
`git diff
${
baseDiffTarget
}
-- "
${
file
}
"`
)
;
if
(
!
diff
.
trim
(
)
)
continue
;
const
prompt
=
[
"You are a translation moderation system."
,
""
,
"Analyze this Android strings.xml git diff."
,
""
,
"Check ONLY newly added or modified translations."
,
""
,
"Detect:"
,
"- profanity"
,
"- slurs"
,
"- hate speech"
,
"- sexual content"
,
"- abusive language"
,
"- offensive slang"
,
""
,
"Ignore:"
,
"- XML syntax"
,
"- placeholders like %s or %d"
,
"- harmless casual language"
,
""
,
"Reply ONLY with:"
,
"SAFE"
,
""
,
"or"
,
""
,
"UNSAFE: <reason>"
,
""
,
"Git diff:"
,
diff
]
.
join
(
"\n"
)
;
try
{
const
result
=
await
model
.
generateContent
(
prompt
)
;
const
text
=
result
.
response
.
text
(
)
.
trim
(
)
;
console
.
log
(
`\n=== Scanning:
${
file
}
===`
)
;
console
.
log
(
text
)
;
if
(
!
text
.
startsWith
(
"SAFE"
)
)
{
workflowFailed
=
true
;
}
}
catch
(
err
)
{
console
.
error
(
`Error scanning
${
file
}
:`
,
err
.
message
)
;
workflowFailed
=
true
;
}
}
if
(
workflowFailed
)
{
console
.
error
(
"\nTranslation moderation failed. Unsafe content detected."
)
;
process
.
exit
(
1
)
;
}
console
.
log
(
"\nAll translations are safe."
)
;
}
main
(
)
.
catch
(
(
err
)
=>
{
console
.
error
(
"Execution error:"
,
err
)
;
process
.
exit
(
1
)
;
}
)
;
You can’t perform that action at this time.