Skip to content

Instantly share code, notes, and snippets.

@justin3737
Last active February 27, 2022 07:38
Show Gist options
  • Save justin3737/fa4abe77e5b15e0765ee57592e9fb8f1 to your computer and use it in GitHub Desktop.
Save justin3737/fa4abe77e5b15e0765ee57592e9fb8f1 to your computer and use it in GitHub Desktop.

Revisions

  1. justin3737 revised this gist May 4, 2018. 1 changed file with 16 additions and 14 deletions.
    30 changes: 16 additions & 14 deletions spell_check.py
    Original file line number Diff line number Diff line change
    @@ -5,33 +5,36 @@
    import re
    # ------------------- Define -------------------
    pat = '[a-zA-Z]+'
    xmlTags = ['value', 'string'] #讀取XML的標籤
    xmlTags = ['String', 'value', 'string']

    # ------------------- 使用字典lib -------------------
    # ------------------- Use lib -------------------
    d = enchant.Dict("en_US")

    # ------------------- 讀取白名單 -------------------
    # ------------------- Load whitelist -------------------
    add_dict = open("exception.txt","r").readlines()
    for line in add_dict:
    d.add(line)

    # ------------------- 讀取XML -------------------
    DOMTree = xml.dom.minidom.parse("MSReportTemplates.en-US.resx")
    # ------------------- Load XML -------------------
    #DOMTree = xml.dom.minidom.parse("StringTable.xml")
    DOMTree = xml.dom.minidom.parse("MSReportTemplates.resx")
    arrData = []
    for tages in xmlTags:
    arrData += DOMTree.getElementsByTagName(tages)

    if len( arrData ) > 0 :
    if len( arrData ) > 0:
    for v in arrData:
    try:
    all = re.findall(pat, v.childNodes[0].data)
    for x in range(len(all)):
    if d.check(all[x]) == False:
    print(all[x])
    if v.childNodes[0].data is not None:
    line = re.findall(pat, v.childNodes[0].data)
    else:
    line = v.attributes['DisplayName'].value
    for x in range(len(line)):
    if d.check(line[x]) is False:
    print(line[x])
    except IndexError:
    print('------------------- Parse L10N XML file error.------------------- ')

    # ------------------- 讀取JS -------------------
    # ------------------- Load JS -------------------
    with open('L10N.update.js') as dataFile:
    data = dataFile.read()
    obj = js2py.eval_js(data)
    @@ -41,5 +44,4 @@
    all = re.findall(pat, obj[key])
    for x in range(len(all)):
    if d.check(all[x]) == False:
    print(all[x])

    print(all[x])
  2. justin3737 revised this gist May 3, 2018. No changes.
  3. justin3737 revised this gist Apr 20, 2018. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions spell_check.py
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    import re
    # ------------------- Define -------------------
    pat = '[a-zA-Z]+'
    xmlTags = ['value', 'string']
    xmlTags = ['value', 'string'] #讀取XML的標籤

    # ------------------- 使用字典lib -------------------
    d = enchant.Dict("en_US")
    @@ -17,17 +17,19 @@

    # ------------------- 讀取XML -------------------
    DOMTree = xml.dom.minidom.parse("MSReportTemplates.en-US.resx")
    values = DOMTree.getElementsByTagName("value")
    arrData = []
    for tages in xmlTags:
    arrData += DOMTree.getElementsByTagName(tages)

    if len( values ) > 0 :
    for v in values:
    if len( arrData ) > 0 :
    for v in arrData:
    try:
    all = re.findall(pat, v.childNodes[0].data)
    for x in range(len(all)):
    if d.check(all[x]) == False:
    print(all[x])
    except IndexError:
    print('Parse L10N XML file error.')
    print('------------------- Parse L10N XML file error.------------------- ')

    # ------------------- 讀取JS -------------------
    with open('L10N.update.js') as dataFile:
  4. justin3737 revised this gist Apr 20, 2018. 1 changed file with 33 additions and 8 deletions.
    41 changes: 33 additions & 8 deletions spell_check.py
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,43 @@
    import enchant
    from xml.dom.minidom import parse
    import xml.dom.minidom
    import js2py
    import re
    # ------------------- Define -------------------
    pat = '[a-zA-Z]+'
    xmlTags = ['value', 'string']

    # ------------------- 使用字典lib -------------------
    d = enchant.Dict("en_US")
    add_dict = open("C:\exception.txt","r").readlines()

    # ------------------- 讀取白名單 -------------------
    add_dict = open("exception.txt","r").readlines()
    for line in add_dict:
    d.add(line)
    js = open("C:\l10n.exceptionModal.js","r").readlines()[2:100]

    d.add("udp")
    # ------------------- 讀取XML -------------------
    DOMTree = xml.dom.minidom.parse("MSReportTemplates.en-US.resx")
    values = DOMTree.getElementsByTagName("value")

    if len( values ) > 0 :
    for v in values:
    try:
    all = re.findall(pat, v.childNodes[0].data)
    for x in range(len(all)):
    if d.check(all[x]) == False:
    print(all[x])
    except IndexError:
    print('Parse L10N XML file error.')

    # ------------------- 讀取JS -------------------
    with open('L10N.update.js') as dataFile:
    data = dataFile.read()
    obj = js2py.eval_js(data)
    dataFile.close()

    for line in js:
    all = re.findall(pat, line)
    for key in obj:
    all = re.findall(pat, obj[key])
    for x in range(len(all)):
    if d.check(all[x]) == False:
    print all[x]
    if d.check(all[x]) == False:
    print(all[x])

  5. justin3737 created this gist Apr 20, 2018.
    18 changes: 18 additions & 0 deletions spell_check.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    import re
    pat = '[a-zA-Z]+'
    d = enchant.Dict("en_US")
    add_dict = open("C:\exception.txt","r").readlines()

    for line in add_dict:
    d.add(line)
    js = open("C:\l10n.exceptionModal.js","r").readlines()[2:100]

    d.add("udp")


    for line in js:
    all = re.findall(pat, line)
    for x in range(len(all)):
    if d.check(all[x]) == False:
    print all[x]