import json, os

base = '/home/szymon/projects/tfb/app/panel/public/resources/lang/page'

new_keys = {
    'pl': {
        'b2b_threshold_active':    'Aktywny próg:',
        'b2b_threshold_banner':    'Dane B2B filtrowane przez próg minimalnej wartości transakcji:',
        'b2b_threshold_banner_sub':'transakcje poniżej progu są traktowane jako sprzedaż detaliczna.',
        'b2b_threshold_note':      'min.',
        'col_desc_retail':         'Przychód brutto z transakcji niebędących B2B (sprzedaż detaliczna). Obliczany jako przychód łączny minus przychód B2B.',
        'col_desc_waste_pct':      'Koszt odpadów i strat produkcyjnych jako % przychodu brutto. Im niższy, tym lepiej.',
        'retail_abbr':             'Retail',
        'retail_sales_col_title':  'Sprzedaż detaliczna (bez transakcji B2B)',
        'waste_cost_label':        'Waste',
        'waste_pct':               'Waste %',
    },
    'en': {
        'b2b_threshold_active':    'Active threshold:',
        'b2b_threshold_banner':    'B2B data filtered by minimum transaction value threshold:',
        'b2b_threshold_banner_sub':'transactions below the threshold are treated as retail sales.',
        'b2b_threshold_note':      'min.',
        'col_desc_retail':         'Gross revenue from non-B2B transactions (retail sales). Calculated as total revenue minus B2B revenue.',
        'col_desc_waste_pct':      'Cost of waste and production losses as % of gross revenue. The lower, the better.',
        'retail_abbr':             'Retail',
        'retail_sales_col_title':  'Retail sales (excl. B2B transactions)',
        'waste_cost_label':        'Waste',
        'waste_pct':               'Waste %',
    },
    'fr': {
        'b2b_threshold_active':    'Seuil actif :',
        'b2b_threshold_banner':    'Données B2B filtrées par seuil de valeur minimale de transaction :',
        'b2b_threshold_banner_sub':'les transactions en dessous du seuil sont traitées comme des ventes au détail.',
        'b2b_threshold_note':      'min.',
        'col_desc_retail':         'Chiffre d\'affaires brut hors transactions B2B (ventes au détail). Calculé comme le revenu total moins le revenu B2B.',
        'col_desc_waste_pct':      'Coût des déchets et pertes de production en % du chiffre d\'affaires brut. Plus c\'est bas, mieux c\'est.',
        'retail_abbr':             'Retail',
        'retail_sales_col_title':  'Ventes au détail (hors transactions B2B)',
        'waste_cost_label':        'Déchets',
        'waste_pct':               'Déchets %',
    },
    'it': {
        'b2b_threshold_active':    'Soglia attiva:',
        'b2b_threshold_banner':    'Dati B2B filtrati per soglia minima del valore della transazione:',
        'b2b_threshold_banner_sub':'le transazioni al di sotto della soglia sono trattate come vendite al dettaglio.',
        'b2b_threshold_note':      'min.',
        'col_desc_retail':         'Ricavi lordi da transazioni non B2B (vendite al dettaglio). Calcolato come ricavi totali meno ricavi B2B.',
        'col_desc_waste_pct':      'Costo degli scarti e delle perdite di produzione come % dei ricavi lordi. Più è basso, meglio è.',
        'retail_abbr':             'Retail',
        'retail_sales_col_title':  'Vendite al dettaglio (escluse transazioni B2B)',
        'waste_cost_label':        'Scarti',
        'waste_pct':               'Scarti %',
    },
    'nl': {
        'b2b_threshold_active':    'Actieve drempel:',
        'b2b_threshold_banner':    'B2B-gegevens gefilterd op minimale transactiewaarde drempel:',
        'b2b_threshold_banner_sub':'transacties onder de drempel worden behandeld als detailhandelsverkopen.',
        'b2b_threshold_note':      'min.',
        'col_desc_retail':         'Bruto-omzet uit niet-B2B-transacties (detailhandel). Berekend als totale omzet minus B2B-omzet.',
        'col_desc_waste_pct':      'Kosten van afval en productieverliezen als % van de bruto-omzet. Hoe lager, hoe beter.',
        'retail_abbr':             'Retail',
        'retail_sales_col_title':  'Detailhandelsverkopen (excl. B2B-transacties)',
        'waste_cost_label':        'Afval',
        'waste_pct':               'Afval %',
    },
}

for lang, keys in new_keys.items():
    path = os.path.join(base, lang, 'analysis.json')
    with open(path) as f:
        data = json.load(f)
    added = []
    for k, v in keys.items():
        if k not in data:
            data[k] = v
            added.append(k)
    # sort keys alphabetically
    data = dict(sorted(data.items()))
    with open(path, 'w') as f:
        json.dump(data, f, ensure_ascii=False, indent=2)
        f.write('\n')
    print(f'[{lang}] added {len(added)} keys: {added}')

