File: extract-loc.py

package info (click to toggle)
azure-cli 2.82.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,359,416 kB
  • sloc: python: 1,910,381; sh: 1,343; makefile: 406; cs: 145; javascript: 74; sql: 37; xml: 21
file content (34 lines) | stat: -rw-r--r-- 1,224 bytes parent folder | download | duplicates (4)
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
#! /usr/bin/env python3
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import os
import re
import subprocess
import sys

from pathlib import Path

ROOT = Path(__file__).resolve().parent.parent / "src" / "azure" / "cli"
OUTPUT = ROOT / "locale" / "en-US" / "messages.txt"

print('Extracting from:', ROOT)

if not ROOT.is_dir():
    print("Failed to locate 'azure/cli'")
    sys.exit(1)

if not OUTPUT.parent.is_dir():
    os.makedirs(str(OUTPUT.parent))

with open(str(OUTPUT), 'w', encoding='utf-8-sig') as f_out:
    for path in ROOT.rglob('*.py'):
        with open(str(path), 'r', encoding='utf-8') as f:
            content = f.read()
        for m in re.finditer(r'[^\w_]_\(("(.+)"|\'(.+)\')\)', content):
            print('# From', path, ':', m.span()[0], file=f_out)
            print('KEY:', m.group(2) or m.group(3), file=f_out)
            print(m.group(2) or m.group(3), file=f_out)
            print(file=f_out)