Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stable Diffusion Webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Stable Diffusion Webui
Commits
cdb1ffb2
Commit
cdb1ffb2
authored
May 13, 2023
by
AUTOMATIC1111
Committed by
GitHub
May 13, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10335 from akx/l10n-dis-take-2
Localization fixes
parents
23b62afc
cd6990c2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
35 deletions
+41
-35
javascript/localization.js
javascript/localization.js
+33
-27
modules/localization.py
modules/localization.py
+2
-2
modules/ui.py
modules/ui.py
+6
-6
No files found.
javascript/localization.js
View file @
cdb1ffb2
...
...
@@ -109,18 +109,23 @@ function processNode(node){
}
function
dumpTranslations
(){
if
(
!
hasLocalization
())
{
// If we don't have any localization,
// we will not have traversed the app to find
// original_lines, so do that now.
processNode
(
gradioApp
());
}
var
dumped
=
{}
if
(
localization
.
rtl
)
{
dumped
.
rtl
=
true
dumped
.
rtl
=
true
;
}
Object
.
keys
(
original_lines
).
forEach
(
function
(
text
){
if
(
dumped
[
text
]
!==
undefined
)
return
dumped
[
text
]
=
localization
[
text
]
||
text
})
for
(
const
text
in
original_lines
)
{
if
(
dumped
[
text
]
!==
undefined
)
continue
;
dumped
[
text
]
=
localization
[
text
]
||
text
;
}
return
dumped
return
dumped
;
}
function
download_localization
()
{
...
...
@@ -137,7 +142,11 @@ function download_localization() {
document
.
body
.
removeChild
(
element
);
}
if
(
hasLocalization
())
{
document
.
addEventListener
(
"
DOMContentLoaded
"
,
function
()
{
if
(
!
hasLocalization
())
{
return
;
}
onUiUpdate
(
function
(
m
)
{
m
.
forEach
(
function
(
mutation
)
{
mutation
.
addedNodes
.
forEach
(
function
(
node
)
{
...
...
@@ -146,26 +155,23 @@ if(hasLocalization()) {
});
})
processNode
(
gradioApp
())
document
.
addEventListener
(
"
DOMContentLoaded
"
,
function
()
{
processNode
(
gradioApp
())
if
(
localization
.
rtl
)
{
// if the language is from right to left,
(
new
MutationObserver
((
mutations
,
observer
)
=>
{
// wait for the style to load
mutations
.
forEach
(
mutation
=>
{
mutation
.
addedNodes
.
forEach
(
node
=>
{
if
(
node
.
tagName
===
'
STYLE
'
)
{
observer
.
disconnect
();
if
(
localization
.
rtl
)
{
// if the language is from right to left,
(
new
MutationObserver
((
mutations
,
observer
)
=>
{
// wait for the style to load
mutations
.
forEach
(
mutation
=>
{
mutation
.
addedNodes
.
forEach
(
node
=>
{
if
(
node
.
tagName
===
'
STYLE
'
)
{
observer
.
disconnect
();
for
(
const
x
of
node
.
sheet
.
rules
)
{
// find all rtl media rules
if
(
Array
.
from
(
x
.
media
||
[]).
includes
(
'
rtl
'
))
{
x
.
media
.
appendMedium
(
'
all
'
);
// enable them
}
for
(
const
x
of
node
.
sheet
.
rules
)
{
// find all rtl media rules
if
(
Array
.
from
(
x
.
media
||
[]).
includes
(
'
rtl
'
))
{
x
.
media
.
appendMedium
(
'
all
'
);
// enable them
}
}
}
)
})
;
})
).
observe
(
gradioApp
(),
{
childList
:
true
})
;
}
}
)
}
}
})
});
}
)).
observe
(
gradioApp
(),
{
childList
:
true
});
}
}
)
modules/localization.py
View file @
cdb1ffb2
...
...
@@ -23,7 +23,7 @@ def list_localizations(dirname):
localizations
[
fn
]
=
file
.
path
def
localization_js
(
current_localization_name
)
:
def
localization_js
(
current_localization_name
:
str
)
->
str
:
fn
=
localizations
.
get
(
current_localization_name
,
None
)
data
=
{}
if
fn
is
not
None
:
...
...
@@ -34,4 +34,4 @@ def localization_js(current_localization_name):
print
(
f
"Error loading localization from {fn}:"
,
file
=
sys
.
stderr
)
print
(
traceback
.
format_exc
(),
file
=
sys
.
stderr
)
return
f
"
var localization = {json.dumps(data)}
\n
"
return
f
"
window.localization = {json.dumps(data)}
"
modules/ui.py
View file @
cdb1ffb2
...
...
@@ -1771,12 +1771,11 @@ def webpath(fn):
def
javascript_html
():
script_js
=
os
.
path
.
join
(
script_path
,
"script.js"
)
head
=
f
'<script type="text/javascript"
src="{webpath(script_js)}">
</script>
\n
'
# Ensure localization is in `window` before scripts
head
=
f
'<script type="text/javascript"
>{localization.localization_js(shared.opts.localization)}
</script>
\n
'
inline
=
f
"{localization.localization_js(shared.opts.localization)};"
if
cmd_opts
.
theme
is
not
None
:
inline
+=
f
"set_theme('{cmd_opts.theme}');"
script_js
=
os
.
path
.
join
(
script_path
,
"script.js"
)
head
+=
f
'<script type="text/javascript" src="{webpath(script_js)}"></script>
\n
'
for
script
in
modules
.
scripts
.
list_scripts
(
"javascript"
,
".js"
):
head
+=
f
'<script type="text/javascript" src="{webpath(script.path)}"></script>
\n
'
...
...
@@ -1784,7 +1783,8 @@ def javascript_html():
for
script
in
modules
.
scripts
.
list_scripts
(
"javascript"
,
".mjs"
):
head
+=
f
'<script type="module" src="{webpath(script.path)}"></script>
\n
'
head
+=
f
'<script type="text/javascript">{inline}</script>
\n
'
if
cmd_opts
.
theme
:
head
+=
f
'<script type="text/javascript">set_theme(
\"
{cmd_opts.theme}
\"
);</script>
\n
'
return
head
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment