-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #560 from thunderbird/v14.0.2
V14.0.2
- Loading branch information
Showing
180 changed files
with
16,903 additions
and
13,138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
python locale-converter.py ..\src\chrome\locale\cs\mboximport ..\src\_locales\cs | ||
|
||
|
||
|
||
python locale-converter.py ..\src\chrome\locale\de\mboximport ..\src\_locales\de | ||
python locale-converter.py ..\src\chrome\locale\ca\mboximport ..\src\_locales\ca | ||
python locale-converter.py ..\src\chrome\locale\da\mboximport ..\src\_locales\da | ||
python locale-converter.py ..\src\chrome\locale\el\mboximport ..\src\_locales\el | ||
python locale-converter.py ..\src\chrome\locale\es-ES\mboximport ..\src\_locales\es-ES | ||
python locale-converter.py ..\src\chrome\locale\fr\mboximport ..\src\_locales\fr | ||
python locale-converter.py ..\src\chrome\locale\gl-ES\mboximport ..\src\_locales\gl-ES | ||
python locale-converter.py ..\src\chrome\locale\hu-HU\mboximport ..\src\_locales\hu-HU | ||
python locale-converter.py ..\src\chrome\locale\hy-AM\mboximport ..\src\_locales\hy-AM | ||
python locale-converter.py ..\src\chrome\locale\it\mboximport ..\src\_locales\it | ||
python locale-converter.py ..\src\chrome\locale\ja\mboximport ..\src\_locales\ja | ||
python locale-converter.py ..\src\chrome\locale\ko-KR\mboximport ..\src\_locales\ko-KR | ||
python locale-converter.py ..\src\chrome\locale\nl\mboximport ..\src\_locales\nl | ||
python locale-converter.py ..\src\chrome\locale\pl\mboximport ..\src\_locales\pl | ||
python locale-converter.py ..\src\chrome\locale\pt-PT\mboximport ..\src\_locales\pt-PT | ||
python locale-converter.py ..\src\chrome\locale\ru\mboximport ..\src\_locales\ru | ||
python locale-converter.py ..\src\chrome\locale\sk-SK\mboximport ..\src\_locales\sk-SK | ||
python locale-converter.py ..\src\chrome\locale\sl-SI\mboximport ..\src\_locales\sl-SI | ||
python locale-converter.py ..\src\chrome\locale\sv-SE\mboximport ..\src\_locales\sv-SE | ||
python locale-converter.py ..\src\chrome\locale\zh-CN\mboximport ..\src\_locales\zh-CN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# This file is provided by the addon-developer-support repository at | ||
# https://github.com/thundernest/addon-developer-support | ||
# | ||
# Version: 1.1 | ||
# | ||
# Author: John Bieling ([email protected]), gNeander | ||
# | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import os, sys, json, re, io, shlex | ||
|
||
#------------------------------------------------ | ||
|
||
def newDir(dir): | ||
if not os.path.exists(dir): | ||
print("Directory doesn't exist. Creating. <" + dir + ">") | ||
os.makedirs(dir) | ||
|
||
def convert(source, destination, current = None, level = 1): | ||
dir = source if current == None else current | ||
messages = [] | ||
|
||
for name in os.listdir(dir): | ||
path = os.path.join(dir, name) | ||
|
||
if os.path.isfile(path): | ||
if path.endswith('profilewizard.dtd'): | ||
messages.extend(convert_dtd(path, dir)) | ||
#if path.endswith('.properties'): | ||
# messages.extend(convert_prop(path, dir)) | ||
|
||
else: | ||
messages.extend(convert(source, destination, path, level+1)) | ||
|
||
if level > 1: | ||
return messages | ||
elif level == 1 and messages: | ||
# map the path from the source into the destination folder | ||
dest = dir.replace(source, destination); | ||
messagesjson = os.path.join(dest, "messages.json") | ||
newDir(dest) | ||
|
||
# check if the messagesjson already exists | ||
oldData = None | ||
if os.path.exists(messagesjson): | ||
with open(messagesjson, "r", encoding='utf-8') as f: | ||
oldData = json.load(f) | ||
|
||
# merge data | ||
newData = json.loads("{" + ", ".join(messages) + "}") | ||
if oldData: | ||
mergedData = oldData | ||
mergedData.update(newData) | ||
else: | ||
mergedData = newData | ||
|
||
# write pretty printed json file | ||
final = json.dumps(mergedData, indent=4, sort_keys=True, ensure_ascii=False) | ||
with io.open(messagesjson, "w", encoding='utf-8') as f: | ||
f.write(final) | ||
print(final) | ||
|
||
# check the file for correctness | ||
print(" -> TESTING " + messagesjson) | ||
with open(messagesjson, "r", encoding='utf-8') as f: | ||
d = json.load(f) | ||
#print(d) | ||
|
||
return [] | ||
|
||
|
||
|
||
def convert_dtd(path, dir): | ||
print(" CONVERTING <" + path + "> to JSON") | ||
|
||
sdtd = [] | ||
|
||
dtd = io.open(path, 'r', encoding='utf-8') | ||
dtdTokens = shlex.split(dtd.read(), posix=False) | ||
|
||
for i, j in enumerate(dtdTokens): | ||
if j == "<!ENTITY": | ||
sdtd.append(' "' + dtdTokens[i+1].strip() +'" : ' + json.dumps({ "message" : dtdTokens[i+2].strip()[1:-1] })) | ||
|
||
return sdtd | ||
|
||
|
||
def convert_prop(path, dir): | ||
print(" CONVERTING <" + path + "> to JSON") | ||
|
||
sprop = [] | ||
prop = io.open(path, 'r', encoding='utf-8') | ||
propLines = prop.readlines() | ||
|
||
for line in propLines: | ||
sline = line.strip().replace('\r','').replace('\n','') | ||
#print("next line >>" + line + "<<") | ||
|
||
if sline != '' and sline[0] != '#': | ||
a = sline.split('=') | ||
|
||
# search for %S and replace them by $P1$, $P2" and so on | ||
count = 0; | ||
placeholders = {}; | ||
while True: | ||
idx = a[1].find("%S") | ||
if (idx == -1): | ||
break | ||
count += 1 | ||
a[1] = a[1].replace("%S", "$P" + str(count) + "$", 1) | ||
placeholders["P" + str(count)] = { "content" : "$" + str(count) } | ||
|
||
data = {} | ||
data["message"] = a[1].strip(); | ||
if len(placeholders) > 0: | ||
data["placeholders"] = placeholders | ||
|
||
sprop.append(' "' + a[0].strip() +'" : ' + json.dumps(data)); | ||
|
||
return sprop | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
print (""" | ||
This python3 script converts legacy locale files (*.properties and *.dtd) | ||
to the new WebExt JSON format.""") | ||
|
||
if (len(sys.argv) < 2 or len(sys.argv) > 3): | ||
print (""" | ||
Legacy WebExt | ||
------ ------ | ||
locale _locales | ||
|__ <languageX> |__ <languageX> | ||
|__ <myaddon.dtd> |__ <messages.json> | ||
|__ <myaddon.properties> | ||
Usage: | ||
py locale-converter.py <source> [<destination>] | ||
If the destination folder (WebExt _locales folder) is not specified, | ||
the specified source folder (legacy locale folder) will be used as | ||
the destination folder. | ||
If there is an existing messages.json at the final destination, the | ||
script will attempt to merge the new strings into it. | ||
Testing: | ||
Each created JSON file is tested with the python function json.load(f), | ||
which will throw an error in case something went wrong. Run a JSON | ||
validator on the created json files to learn more about the error. | ||
JSON Validators: | ||
https://jsonlint.com/ | ||
http://jsoneditoronline.org/ | ||
https://jsonformatter.curiousconcept.com/ | ||
""") | ||
|
||
exit() | ||
|
||
# use source as destination, if not specified | ||
source = sys.argv[1]; | ||
destination = sys.argv[1]; | ||
if (len(sys.argv) == 3): | ||
destination = sys.argv[2]; | ||
|
||
convert(source, destination) | ||
|
||
print( """Done""") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.