add multi language support to gen-license
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
from argparse import ArgumentParser
|
||||
from argparse import ArgumentParser, _HelpAction
|
||||
from pkgutil import get_data
|
||||
from sys import exit
|
||||
|
||||
@ -36,15 +36,38 @@ def getparser():
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--996icu", dest="icu", help="Expand LICENSE with 996ICU LICENSE", required=False,
|
||||
action="store_true"
|
||||
"--996icu", dest="icu", help="Expand LICENSE with 996ICU LICENSE, Choose a language vesion or default zh-cn",
|
||||
required=False, nargs="?", const="zh-cn", default=None,
|
||||
choices=["en-us", "zh-cn"]
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
def select_template(language_code):
|
||||
"""choose a 996icu LICENSE template according to *language_code*
|
||||
"""
|
||||
map_ = {
|
||||
"zh": "zh-cn",
|
||||
"zh-cn": "zh-cn",
|
||||
"zh-hans": "zh-cn",
|
||||
"en": "en-us",
|
||||
"en-us": "en-us",
|
||||
}
|
||||
|
||||
template = get_data(
|
||||
__package__,
|
||||
"licenses/996.icu.template.{}.txt".format(
|
||||
map_.get(language_code, "zh-cn")
|
||||
)
|
||||
).decode("utf-8")
|
||||
|
||||
return template
|
||||
|
||||
|
||||
def main():
|
||||
args = getparser().parse_args()
|
||||
parser = getparser()
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.list:
|
||||
for license in LICENSES:
|
||||
@ -53,16 +76,18 @@ def main():
|
||||
exit(0)
|
||||
else: # main
|
||||
|
||||
# if no args input, show help and exit
|
||||
if args.code is None:
|
||||
parser.print_help()
|
||||
parser.exit()
|
||||
|
||||
resource = get_data(
|
||||
__package__,
|
||||
"licenses/{code}.txt".format(code=args.code)
|
||||
).decode("utf-8")
|
||||
|
||||
if args.icu: # --996icu option enabled
|
||||
template = get_data(
|
||||
__package__,
|
||||
"licenses/996.icu.template.zh-cn.txt"
|
||||
).decode("utf-8")
|
||||
if args.icu is not None: # --996icu option enabled
|
||||
template = select_template(args.icu)
|
||||
|
||||
output = template.format(
|
||||
other=args.code,
|
||||
@ -70,7 +95,7 @@ def main():
|
||||
).encode("utf-8")
|
||||
|
||||
else: # common license
|
||||
output = resource
|
||||
output = resource.encode("utf-8")
|
||||
|
||||
with open("LICENSE", "wb") as file:
|
||||
file.write(output)
|
||||
|
@ -0,0 +1,31 @@
|
||||
Copyright © 2019 <copyright holders>
|
||||
The 996ICU License (996ICU)
|
||||
|
||||
996ICU License is an extented license for {other}.
|
||||
This license extended {other}, and {other} will be declared at the foot of this license.
|
||||
|
||||
Individual who seeks authorization must fulfill the following obligations:
|
||||
|
||||
1. Including this authorization file in any of its copies and important parts of the software.
|
||||
|
||||
Organization that seeks authorization must fulfill the following obligations:
|
||||
|
||||
1. Including this authorization file in any of its copies and important parts of the software.
|
||||
2. Not forcing any employee or temporary worker to work in excess of the legal maximum working time in any form or by any means, including but not limited to: orders, threats, implications, etc.
|
||||
3. Not retaliating against any employee or temporary worker without participating in labor in excess of the legal maximum working time in any form or by any means, including but not limited to: mental assaults, personal injuries, illegal deductions of due remuneration, illegal dismissals, etc.
|
||||
4. Paying economic compensation at no lower than the standards stipulated by local laws and regulations, when organizing employees or temporary workers to work overtime.
|
||||
5. This organization is not in the blacklist[^1] as stipulated in the agreement.
|
||||
|
||||
If the authorized individual or organization fails to fulfill any of the above obligations, the authorization will be withdrawn.
|
||||
|
||||
The undefined behavior of this license is handled by {other}. The part of {other} that conflicts with this agreement is handled in accordance with this agreement.
|
||||
|
||||
|
||||
* Discussion https://github.com/996icu/996.ICU/pull/15642
|
||||
* 996 from https://feathub.com/LinXueyuanStdio/996.ICU
|
||||
* [^1]: blacklist https://github.com/996icu/996.ICU/blob/master/blacklist/blacklist.md
|
||||
|
||||
{other}
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
{content}
|
Reference in New Issue
Block a user