import re
from pathlib import Path

import django
from django.conf.locale import LANG_INFO
from django.core.exceptions import ObjectDoesNotExist
from django.core.management.base import BaseCommand
from django.utils.translation import gettext as _

from translate.core.utils.logger import log
from translate.service.models import Language, Translation, TranslationKey

CUSTOM_OCCURRENCES = "new_mdt/custom_translation.py"
FORM_FIELD_OCCURRENCES = "new_mdt/form_field_translation.py"

CUSTOM_TRANSLATION = [
    _("This field is required."),
    _("Previous"),
    _("Next"),
    _("is_advertised"),
    _("min_occupancy"),
    _("apartment"),
    _("max_adult"),
    _("min_adult"),
    _("max_child"),
    _("min_child"),
    _("image"),
    _("pdf_file"),
    _("capital_share"),
    _("vacancies"),
    _("tender_notice"),
    _("building"),
    _("assignment_direct"),
    _("create_advert"),
    _("min_occupancy_info"),
    _("num_applications"),
    _("reference_date"),
    _("rentalgross"),
    _("rentalgross_net"),
    _("sel"),
    _("subsidized"),
    _("all_offers"),
    _("assignment_apartment"),
    _("assignment_other"),
    _("assignment_parkingspace"),
    _("children"),
    _("evaluation_overall_comment"),
    _("evaluation_priority"),
    _("korrespondenz_per_post"),
    _("mail_history"),
    _("modiftrue"),
    _("number_of_declined"),
    _("number_of_declined_tenant"),
    _("modified"),
    _("createdUG"),
    _("relocationrequest"),
    _("proposions"),
    _("number_of_uninterested_tenant"),
    _("balcony"),
    _("parterre"),
    _("elevator"),
    _("number_of_offers"),
    _("prio_ids"),
    _("prios"),
    _("subvention_income"),
    _("subvention_wealth"),
    _("subvention_residence"),
    _("voucher_code"),
    _("recall"),
    _("assignment_detail"),
    _("assignment_parking"),
    _("assignment_state"),
    _("contact_tel"),
    _("umzugsgrund"),
    _("created"),
    _("befristed"),
    _("assignment_single"),
    _("ref"),
    _("application_id"),
    _("employer"),
    _("enforcement_doc"),
    _("in_education"),
    _("Confirmation"),
    _("Mail Signature"),
    _("Postmark Sender Name"),
    _("sum_bicycles"),
    _("history"),
    _("parking"),
    _("mail history"),
    _("actions"),
    _("property_type"),
    _("state"),
    _("Create"),
    _("Cooperative Experience"),
    _("You have not completed all mandatory fields"),
    _("Application"),
    _("living_since"),
    _("previous_rent"),
    _("incidental_costs"),
    _("income_gros"),
    _("company_since"),
    _("Address"),
    _("valid"),
    _("area"),
    _("notice_of_termination"),
    _("Create Apartment"),
    _("Is Advertised"),
    _("Additional Room For Prio 1"),
    _("Additional Room For Prio 2"),
    _("Additional Room For Prio 3"),
    _("Hobbyroom"),
    _("Household Structure"),
    _("Applicants"),
    _("Rental Properties"),
    _("Mobility"),
    _("Additional"),
    _("Send Application"),
    _("Contract"),
    _("All assigments"),
    _("Assignment Parking"),
    _("points"),
    _("Num Children"),
    _("Additional Room"),
    _("Parking"),
    _("false"),
    _("true"),
    _("street nr"),
    _("city"),
    _("moving date"),
    _("solvent"),
    _("wants hobbyroom"),
    _("evaluation priority"),
    _("assignment"),
    _("agreement references"),
    _("active prio title temp"),
    _("occupation"),
    _("date_of_birth"),
    _("postcode"),
    _("company_phone"),
    _("firstname"),
    _("member_since"),
    _("income_gross"),
    _("membership_id"),
    _("company"),
    _("company_postcode"),
    _("legal_residence"),
    _("nation"),
    _("email"),
    _("civil_status"),
    _("company_city"),
    _("landlordphone"),
    _("office_phone"),
    _("phone"),
    _("member"),
    _("permit"),
    _("highest_education"),
    _("street_nr"),
    _("same_address"),
    _("adress"),
    _("same_address"),
    _("days_present"),
    _("subventions_tax"),
    _("adress_2yago"),
    _("overall_evaluation"),
    _("evaluation_overall_star"),
    _("True"),
    _("False"),
    _("household_social_mix"),
    _("income_comment"),
    _("household_second_evaluation"),
    _("income_needs_clarfication"),
    _("instrument_needs_clarification"),
    _("instrument_comment"),
    _("instrument_second_evaluation"),
    _("references_needs_clarification"),
    _("references_second_evaluation"),
    _("references_ok"),
    _("documents_comment"),
    _("documents_second_evaluation"),
    _("documents_ok"),
    _("finance_needs_clarification"),
    _("finance_comment"),
    _("finance_ok"),
    _("validity_needs_clarification"),
    _("validity_comment"),
    _("validity_second_evaluation"),
    _("validity_ok"),
    _("experience_ok"),
    _("occupancy_comment"),
    _("occupancy_needs_clarification"),
    _("occupancy_prio_1"),
    _("occupancy_prio_2"),
    _("occupancy_prio_3"),
    _("occupancy_second_evaluation"),
    _("overall_evaluation_second_evaluator"),
    _("overall_evaluation_comment"),
    _("overall_evaluation_done"),
    _("overall_evaluation_second_evaluator_done"),
    _("overall_needs_clarification"),
    _("overall_comment"),
    _("parking_ok"),
    _("pets_needs_clarification"),
    _("pets_comment"),
    _("pets_second_evaluation"),
    _("solvency_prio_1"),
    _("solvency_prio_2"),
    _("solvency_prio_3"),
    _("solvency_comment"),
    _("solvency_needs_clarification"),
    _("solvency_second_evaluation"),
    _("solvency_financial_conditions"),
    _("mobility_traffic_behavior"),
    _("mobility_second_evaluation"),
    _("mobility_needs_clarification"),
    _("mobility_ok"),
    _("cooperative_experience"),
    _("cooperative_commitment"),
    _("residency_rights_values"),
    _("experience_needs_clarification"),
    _("experience_comment"),
    _("experience_second_evaluation"),
    _("experience_comment"),
    _("experience_second_evaluation"),
    _("commitment_comment"),
    _("commitment_needs_clarification"),
    _("commitment_second_evaluation"),
    _("further_information_comment"),
    _("further_information_second_evaluation"),
    _("further_information_needs_clarification"),
    _("presentation_comment"),
    _("presentation_impression"),
    _("car_evaluation"),
    _("presentation_attended"),
    _("presentation_invited"),
    _("urgency"),
    _("neighborhood"),
    _("general_commitment"),
    _("future_commitment"),
    _("living_and_working"),
    _("second_evaluator"),
    _("dog"),
    _("income_needs_clarification"),
    _("finance_second_evaluation"),
    _("recall_date"),
    _("relocation_reason"),
    _("number_ebicycles"),
    _("workshop_intended_use"),
    _("engagement"),
    _("num_ecars"),
    _("number_bicycles"),
    _("source_reason"),
    _("addroom"),
    _("source_reason"),
    _("numcars"),
    _("pets_detail"),
    _("remarks"),
    _("agreement_references"),
    _("hobbyroom_intended_use"),
    _("household_type"),
    _("number_moped"),
    _("parking_num_cars"),
    _("source"),
    _("wants_hobbyroom"),
    _("wants_workshop"),
    _("nummotorbikes"),
    _("ug_status"),
    _("actualisation"),
    _("userconfirmation"),
    _("userinactive"),
    _("parking_num_cars"),
    _("employment_quota"),
    _("Garage"),
    _("on"),
    _("references_comment"),
    _("country"),
    _("documents_needs_clarification"),
    _("enforcement_doc_mail"),
    _("Additional Room"),
    _("send_mail"),
    _("denied_mail"),
    _("denied_no_prios"),
    _("reminder"),
    _("tenant_info"),
    _("reminder"),
    _("relocation_confirmation_link"),
    _("relocation_confirmation_without_link"),
    _("relocation_offer_link"),
    _("relocation_offer_without_link"),
    _("relocation_acceptance"),
    _("relocation_declining"),
    _("Enforcement OK"),
    _("Landlord Contact"),
    _("Landlord Payment"),
    _("Landlord Terminated"),
    _("Landlord Terminated Date"),
    _("Work Date"),
    _("Employed By"),
    _("Work Since"),
    _("Work Terminated"),
    _("Work Terminated Date"),
    _("Work Salary"),
    _("Permit OK"),
    _("Needs Evaluation"),
    _("Design"),
    _("employee"),
    _("evaluator"),
    _("manager"),
    _("team_leader"),
    _("user_read"),
    _("user_write"),
    _("applications_read"),
    _("applications_write"),
    _("evaluations_read"),
    _("evaluations_write"),
    _("masterdata_read"),
    _("masterdata_write"),
    _("assignments_read"),
    _("assignments_write"),
    _("analytics_read"),
    _("insurance_read"),
    _("axa_client"),
    _("insurance_private"),
    _("axa_client_id"),
    _("insurance_home"),
    _("insurance_agent"),
    _("admin_read"),
    _("export_data"),
    _("send_mails"),
    _("get_references"),
    _("config_view"),
    _("execute_random"),
    _("change_state"),
    _("import_data"),
    _("offer_read"),
    _("objectdata_read"),
    _("analytics_write"),
    _("admin_write"),
    _("newtenant_offer_link"),
    _("newtenant_offer_without_link"),
    _("newtenant_acceptance"),
    _("send_offer_denied"),
    _("send_offer_accepted"),
    _("offer_reminder"),
    _("newtenant_confirmation_without_link"),
    _("newtenant_confirmation_link"),
    _("newtenant_declining"),
    _("newtenant_declining_no_prios_without_link"),
    _("newtenant_declining_no_prios_link"),
    _("to_6"),
    _("to_12"),
    _("to_18"),
    _("to_24"),
    _("to_30"),
    _("to_36"),
    _("to_180"),
    _("move in date"),
    _("num ecars"),
    _("number bicycles"),
    _("number ebicycles"),
    _("music instruments"),
    _("wants mobility"),
    _("relocation reason"),
    _("subvention residence since"),
    _("source reason"),
    _("apartment visited"),
    _("household type"),
    _("subvention wealth"),
    _("subvention income"),
    _("parking num cars"),
    _("stockroom intended use"),
    _("pets detail"),
    _("car reason"),
    _("hobbyroom intended use"),
    _("source web"),
    _("addroom intended use"),
    _("music instruments type"),
    _("agreement deposit"),
    _("workshop intended use"),
    _("car documentation"),
    _("motorbikes"),
    _("securities"),
    _("number cycle trailer"),
    _("motivation"),
    _("family apartment"),
    _("number moped"),
    _("insurance"),
    _("deposit"),
    _("is advertised"),
    _("in education"),
    _("company since"),
    _("income gross"),
    _("membership id"),
    _("notice of termination"),
    _("application id"),
    _("office phone"),
    _("subventions tax"),
    _("legal residence"),
    _("company city"),
    _("living since"),
    _("adress 2yago"),
    _("enforcement"),
    _("living arrangements"),
    _("rental"),
    _("member since"),
    _("tenant type"),
    _("civil status"),
    _("enforcement doc"),
    _("company postcode"),
    _("previous rent"),
    _("company phone"),
    _("employment quota"),
    _("Validity"),
    _("enforcement monthly rate"),
    _("permit doc"),
    _("sum bicycles"),
    _("voucher code"),
    _("evaluation overall comment"),
    _("max adult"),
    _("capital share"),
    _("tender notice"),
    _("min adult"),
    _("pdf file"),
    _("max child"),
    _("min child"),
    _("Apartment"),
    _("Parkingspace"),
    _("Other"),
    _("EvaluationEvaluatorsForm"),
    _("EvaluationHouseholdForm"),
    _("EvaluationObjectsForm"),
    _("EvaluationSolvencyForm"),
    _("EvaluationMobilityForm"),
    _("EvaluationEmployerReferencesForm"),
    _("EvaluationLandlordReferencesForm"),
    _("EvaluationInstrumentsForm"),
    _("EvaluationFinanceForm"),
    _("EvaluationAnimalsForm"),
    _("EvaluationFurtherInformationForm"),
    _("EvaluationDocumentsForm"),
    _("EvaluationSummaryForm"),
    _("EvaluationEventForm"),
    _("SecondEvaluationSummaryForm"),
    _("EvaluationValidityForm"),
    _("EvaluationApplicantCommentForm"),
    _("EvaluationMotivationForm"),
    _("EvaluationPriorityForm"),
    _("EvaluationSubsidyForm"),
    _("EvaluationExperienceForm"),
    _("EvaluationCommitmentForm"),
    _("active.in_progress"),
    _("active.needs_discussion"),
    _("active.new"),
    _("active.evaluated"),
    _("active.new_customer"),
    _("vacant"),
    _("with_applications"),
    _("without_applications"),
    _("parkingspace"),
    _("object_type"),
    _("object type"),
    _("other"),
    _("active.open"),
    _("active.sent"),
    _("final"),
    _("living_arrangements"),
    _("tenant_type"),
    _("occupancy_evaluation_prio_1"),
    _("overall_flag"),
    _("overall_rejection_reason"),
    _("overall_star"),
    _("household_evaluation"),
    _("household_flag"),
    _("household_rejection_reason"),
    _("instrument_evaluation"),
    _("instrument_flag"),
    _("instrument_rejection_reason"),
    _("landlord_references_flag"),
    _("landlord_references_rejection_reason"),
    _("landlord_references_needs_clarification"),
    _("employer_references_flag"),
    _("employer_references_rejection_reason"),
    _("employer_references_needs_clarification"),
    _("documents_evaluation"),
    _("documents_flag"),
    _("documents_rejection_reason"),
    _("finance_evaluation"),
    _("finance_flag"),
    _("finance_rejection_reason"),
    _("validity_evaluation"),
    _("validity_flag"),
    _("validity_rejection_reason"),
    _("occupancy_evaluation_prio_2"),
    _("occupancy_evaluation_flag"),
    _("occupancy_evaluation_rejection_reason"),
    _("occupancy_evaluation_needs_clarification"),
    _("occupancy_evaluation_prio_3"),
    _("pets_evaluation"),
    _("pets_flag"),
    _("pets_rejection_reason"),
    _("solvency_evaluation_prio_1"),
    _("solvency_evaluation_prio_2"),
    _("solvency_evaluation_prio_3"),
    _("solvency_evaluation_flag"),
    _("solvency_evaluation_rejection_reason"),
    _("solvency_evaluation_needs_clarification"),
    _("mobility_evaluation"),
    _("mobility_flag"),
    _("mobility_rejection_reason"),
    _("experience_evaluation"),
    _("experience_flag"),
    _("experience_rejection_reason"),
    _("commitment_evaluation"),
    _("commitment_flag"),
    _("commitment_rejection_reason"),
    _("urgency_evaluation"),
    _("urgency_flag"),
    _("urgency_rejection_reason"),
    _("urgency_needs_clarification"),
    _("presentation_evaluation"),
    _("presentation_flag"),
    _("presentation_rejection_reason"),
    _("presentation_needs_clarification"),
    _("priority_evaluation"),
    _("priority_flag"),
    _("priority_rejection_reason"),
    _("priority_needs_clarification"),
    _("motivation_evaluation"),
    _("applicant_comment_evaluation"),
    _("applicant_comment_flag"),
    _("applicant_comment_rejection_reason"),
    _("applicant_comment_needs_clarification"),
    _("singleroom_evaluation"),
    _("singleroom_flag"),
    _("singleroom_rejection_reason"),
    _("singleroom_needs_clarification"),
    _("craftroom_evaluation"),
    _("craftroom_flag"),
    _("craftroom_rejection_reason"),
    _("craftroom_needs_clarification"),
    _("studio_evaluation"),
    _("studio_flag"),
    _("studio_rejection_reason"),
    _("studio_needs_clarification"),
    _("subsidy_evaluation"),
    _("subsidy_flag"),
    _("subsidy_rejection_reason"),
    _("subsidy_needs_clarification"),
    _("overall_comment_second_evaluator"),
    _("landlord_references_comment"),
    _("employer_references_comment"),
    _("occupancy_evaluation_comment"),
    _("solvency_evaluation_comment"),
    _("mobility_comment"),
    _("urgency_comment"),
    _("priority_comment"),
    _("motivation_flag"),
    _("motivation_rejection_reason"),
    _("motivation_needs_clarification"),
    _("motivation_comment"),
    _("applicant_comment_comment"),
    _("singleroom_comment"),
    _("craftroom_comment"),
    _("studio_comment"),
    _("subsidy_comment"),
    _("subsidy_needs_clarification"),
    _("no_pub"),
    _("active.signed"),
    _("active.open"),
    _("active.sent"),
    _("with_offers"),
    _("car_reason"),
    _("move_in_date"),
    _("source_web"),
    _("wants_mobility"),
    _("wants_stockroom"),
    _("family_apartment"),
    _("wants_mobility"),
    _("agreement_deposit"),
    _("apartment_visited"),
    _("car_documentation"),
    _("music_instruments"),
    _("addroom_intended_use"),
    _("number_cycle_trailer"),
    _("addroom_intended_use"),
    _("music_instruments_type"),
    _("stockroom_intended_use"),
    _("subvention_residence_since"),
    _("wants_addroom"),
    _("moving_date"),
    _("with_feedback"),
    _("without_feedback"),
    _("create_task"),
    _("adults_only_name"),
    _("children_only_name"),
    _("virtual"),
    _("pub_start"),
    _("pub_end"),
    _("title_without_link"),
    _("building_adress"),
    _("overall_evaluation_marks"),
    _("evaluation_state"),
    _("evaluation_marks_each"),
    _("evaluation_favorite"),
    _("direct_assigment"),
    _("adults"),
    _("active_prio_title_temp"),
    _("active_prio_listing"),
    _("prios_with_property_type"),
    _("enforcement_monthly_rate"),
    _("landlord_ref"),
    _("permit_doc"),
    _("pub start"),
    _("pub end"),
    _("title without link"),
    _("building adress"),
    _("overall evaluation marks"),
    _("evaluation state"),
    _("evaluation marks each"),
    _("evaluation favorite"),
    _("direct_assigment"),
    _("active prio title temp"),
    _("active prio listing"),
    _("prios with property type"),
    _("enforcement monthly rate"),
    _("landlord ref"),
    _("permit doc"),
    _("adults only name"),
    _("children only name"),
    _("overall evaluation"),
    _("create task"),
    _("other_succesions"),
    _("collectable_interests"),
    _("start_date"),
    _("application"),
    _("assignment_date"),
    _("answer"),
    _("voucher"),
    _("application"),
    _("comments"),
    _("occupation_detail"),
    _("place_of_citizenship"),
    _("has_acceptance"),
    _("has_offer"),
    _("number_of_no_response"),
    _("random_seleted"),
    _("state_of_process"),
    _("flag"),
    _("has_offer"),
    _("random_seleted"),
    _("state_of_process"),
    _("ug_status"),
    _("ug_property_type"),
    _("actual"),
    _("HouseholdListView"),
    _("all assigned"),
    _("assigment_other"),
    _("assigment_parking"),
    _("all"),
    _("with_r"),
    _("without_r"),
    _("hh_r"),
    _("form_id"),
    _("min_max"),
    _("saved_data"),
    _("second_form_id"),
    _("team"),
    _("temp.first_application"),
    _("temp.first_application_inspection"),
    _("temp.first_application_inspection_present"),
    _("was there"),
    _("was_there"),
    _("sum_bicycles_dypoints"),
    _("prio_1_min_income_fulfilled_dypoints"),
    _("prio_1_max_income_fulfilled_dypoints"),
    _("num_children_dypoints"),
    _("num_children"),
    _("num_adults_dypoints"),
    _("num_adults"),
    _("household_income_dypoints"),
    _("household_income"),
    _("state_dypoints"),
    _("incidentals"),
    _("Parking_add"),
    _("randomlog"),
    _("num_inspection"),
    _("prio_1_household_type_fulfilled_dypoints"),
    _("prio_1_age_structure_fulfilled_dypoints"),
    _("EvaluationCraftroomForm"),
    _("EvaluationSingleroomForm"),
    _("EvaluationStudioForm"),
    _("total_points"),
    _("Einfach"),
    _("einfach"),
    _("fehlerhaft"),
    _("versendet"),
    _("landlord_reference_call"),
    _("child"),
    _("adult"),
    _("notify_type"),
    _("notify_date"),
    _("created_by_staff"),
    _("active_prio_apartment_count"),
    _("adult_ages"),
    _("adult_names"),
    _("all_assigned"),
    _("building_title"),
    _("children_ages"),
    _("children_present"),
    _("evaluation_enforcement_doc"),
    _("evaluation_impression"),
    _("evaluation_needs_clarification"),
    _("evaluation_overall"),
    _("evaluation_permit_doc"),
    _("has_free_prios"),
    _("is_assigned"),
    _("list_enforcement_docs"),
    _("names"),
    _("num_men"),
    _("num_refs_employer_ok"),
    _("num_refs_landlord_ok"),
    _("num_women"),
    _("pretty_num_rooms_prio_1"),
    _("pretty_num_rooms_prio_2"),
    _("pretty_num_rooms_prio_3"),
    _("pretty_rent_percentage_prio_1"),
    _("pretty_rent_percentage_prio_2"),
    _("pretty_rent_percentage_prio_3"),
    _("pretty_rent_prio_1"),
    _("pretty_rent_prio_2"),
    _("pretty_rent_prio_3"),
    _("pretty_visited"),
    _("prio_1_age_structure_fulfilled"),
    _("prio_1_household_type_fulfilled"),
    _("prio_1_max_fortune_fulfilled"),
    _("prio_1_max_income_fulfilled"),
    _("prio_1_min_fortune_fulfilled"),
    _("prio_1_min_income_fulfilled"),
    _("prio_ids"),
    _("type"),
    _("wealth_net"),
    _("age"),
    _("fullname"),
    _("fullname_address"),
    _("fullname_birthday"),
    _("type"),
    _("fullname_short"),
    _("is_assigned"),
    _("has_enforcement_doc"),
    _("letter_post"),
    _("pretty_flat"),
    _("pretty_formal"),
    _("pretty_other"),
    _("pretty_parking"),
    _("pretty_title"),
    _("sex"),
    _("type"),
    _("valid_evaluation"),
    _("application"),
    _("prio_1_property_type"),
    _("Year of construction"),
    _("Min max rooms"),
    _("Min max miete"),
    _("craft"),
    _("Craft"),
    _("Allow edit"),
    _("Allow delete"),
    _("Show reloaction"),
    _("Show objects"),
    _("Show waitlist"),
    _("employee_contract"),
    _("employee_reception"),
    _("employee_viewing"),
    _("admin"),
    _("customer"),
    _("Object Representation"),
    _("timestamp"),
    _("actor"),
    _("landlord_reference"),
    _("landlord_reference_reminder"),
    _("employer_reference"),
    _("employer_reference_reminder"),
    _("denied_rent"),
    _("offer"),
    _("offer_alternative"),
    _("colony"),
    _("adress"),
    _("City"),
    _("filter location"),
    _("filter rooms"),
    _("filter rent"),
    _("filter elevator"),
    _("filter floor"),
    _("filter property type"),
    _("app_ang"),
    _("app_act"),
    _("app_ver"),
    _("app_ohn"),
    _("new_evaluated"),
    _("new_application"),
    _("application_state_donut"),
    _("vacant_apartment"),
    _("applications_by_household"),
    _("vega_test"),
    _("origin_map"),
    _("table_when"),
    _("age_income"),
    _("age_pyramid"),
    _("household_radar"),
    _("rent_roi"),
    _("rental_divider"),
    _("publicity_divider"),
    _("demography_divider"),
    _("finance_divider"),
    _("age_gender_violin"),
    _("nation_bfs_bubble"),
    _("commitment_with_contract"),
    _("commitment_without_contract"),
    _("declined_today"),
    _("in_progress"),
    _("with_offer"),
    _("reason_customer"),
    _("canton_map"),
    _("clock"),
    _("nation_bubble"),
    _("nation_bubble_bfs"),
    _("ht_be_bo"),
    _("offer_numbers"),
    _("household_bar"),
    _("min_max_rooms"),
    _("min_max_miete"),
    _("price_sensivity_by_prio"),
    _("sunburst_test"),
    _("open_todos"),
    _("mail_numbers"),
    _("income_rent_heat"),
    _("process_steps"),
    _("age_be_bo"),
    _("nat_be_bo"),
    _("age_class_state_heat"),
    _("age_10_0"),
    _("age_0_4"),
    _("age_5_9"),
    _("age_10_14"),
    _("age_15_19"),
    _("age_20_29"),
    _("age_30_39"),
    _("age_40_49"),
    _("age_50_64"),
    _("age_65_79"),
    _("age_80_120"),
    _("parkingspace_numbers"),
    _("offer_user_numbers"),
    _("first_name"),
    _("username"),
    _("last_name"),
    _("role_text"),
    _("confirmation"),
    _("is_active"),
    _("role"),
    _("teams"),
    _("co_businessplan_doc"),
    _("co_certificate_of_registration"),
    _("co_enforcement_doc"),
    _("co_bylaws_doc"),
    _("reason"),
    _("basement_area"),
    _("Usage"),
    _("employer_reference_call"),
    _("has_no_waitlist_offer_for"),
    _("total_points_swm"),
    _("wealth_gross"),
    _("documents_saved"),
    _("good_salary"),
    _("offer_write"),
    _("objectdata_read"),
    _("objectdata_write"),
    _("get_references"),
    _("add_application"),
    _("export_data"),
    _("change_state"),
    _("send_mails"),
    _("execute_random"),
    _("import_data"),
    _("config_view"),
    _("cost_prov"),
    _("cost_def"),
    _("cost_pred"),
    _("household_income"),
    _("same_adress"),
    _("initial_training"),
    _("initial_training_until"),
    _("co_name"),
    _("co_vat"),
    _("co_vat_number"),
    _("landlordmail"),
    _("employermail"),
    _("employment_contract_terminated"),
    _("employment_contract_terminated_detail"),
    _("send_offer_date"),
    _("tenant_reaction_date"),
    _("valid_till"),
    _("assigment_created"),
    _("pdf_floor_plan"),
    _("object_info"),
    _("entry_date"),
    _("application_info"),
    _("mail_problems"),
    _("acceptance_today"),
    _("measure_category_stacked"),
    _("count_apa_state_icons"),
    _("internet_source"),
    _("source"),
    _("count_apa_state_parkingspace"),
    _("count_apa_state_other"),
    _("apartment_state_donut"),
    _("letting_state_by_date"),
    _("apartment_state_by_room"),
    _("denial_by_reason"),
    _("Checkbox select multiple"),
    _("Float"),
    _("Content text"),
    _("honorary_percent"),
    _("last_edited"),
    _("info"),
    _("employer_reference_date"),
    _("email_control"),
    _("landlord_reference_date"),
    _("employer_reference_number"),
    _("landlord_reference_number"),
    _("has_offer_reason"),
    _("side_info_communication"),
    _("parking_type"),
    _("doc_notice_of_termination"),
    _("prio_1_max_fortune_fulfilled_dypoints"),
    _("prio_1_min_fortune_fulfilled_dypoints"),
    _("child_doc"),
    _("relocation_reason_detail"),
    _("relocation_reason_occupancy"),
    _("relocation_reason_rent"),
    _("relocation_reason_termination"),
    _("simple"),
    _("Simple"),
    _("already_tenant"),
    _("household_income"),
    _("occupancy_denseness"),
    _("rent_burden"),
    _("has_offer_link"),
    _("already_tenant"),
    _("notice_of_termination_detail"),
    _("current_rooms"),
    _("current_rent"),
    _("sightseeing_schedule"),
    _("apply_button"),
    _("plz"),
    _("building_title_multiselect"),
    _("prio_1_rooms"),
    _("date_of_assigment"),
    _("wants_parking"),
    _("car_doc"),
    _("subvention_doc"),
    _("employment_contract"),
    _("offer_send_mail"),
    _("movie_in_date_back"),
    _("pretty_rent_percentage_prio_1_dypoints"),
    _("notice_of_termination_doc"),
    _("bfu_regions_multiselect"),
    _("bfu_regions"),
    _("contract"),
    _("side_info_points"),
    _("metropolitan"),
    _("Building"),
    _("Usage"),
    _("joint_tax_return"),
    _("certificate_of_unpaid_debts"),
    _("obstacle_free"),
    _("applicant_list"),
    _("direct_select_output"),
    _("direct_select"),
    _("direct_select_with_comment"),
    _("side_info_points_swm"),
    _("random_select"),
    _("rent_interest_charge"),
    _("Property type"),
    _("publicated_adress"),
    _("create_object_application"),
    _("academic_title"),
    _("additional_doc"),
    _("assigment_application_date"),
    _("assigment_start_date"),
    _("honorary"),
    _("honorary_charging"),
    _("mv_assigment"),
    _("mv_sent"),
    _("mv_signed"),
    _("parking_assigment"),
    _("tenant_names"),
    _("year_rentalgross_net"),
    _("year_rentalgross_net_is"),
    _("year_rentalgross_net_square"),
    _("co_area"),
    _("location"),
    _("craft_type"),
    _("time_apartment_search"),
    _("personal_liability_insurance"),
    _("household_insurance"),
    _("wants_rooftop"),
    _("rooftop"),
    _("securities_details_name"),
    _("television_provider"),
    _("television_provider_detail"),
    _("attachments"),
    _("citizen"),
    _("user_feedback"),
    _("car_license_plate_number"),
    _("intended_use"),
    _("adult_id"),
    _("bounce"),
    _("houselhold_id"),
    _("letter"),
    _("message_id"),
    _("msg"),
    _("notify"),
    _("household_id"),
    _("application_select"),
    _("log_select"),
    _("view_select"),
    _("relocation_select"),
    _("message_de"),
    _("signature_de"),
    _("subject_de"),
    _("number_adults"),
    _("number_children"),
    _("swm_doc"),
    _("swm_sub_doc"),
    _("number_of_declining_tenant"),
    _("number_of_declining_landlord"),
    _("site_title"),
    _("project_name"),
    _("contact_tel_number"),
    _("contact_mail_adress"),
    _("contact_address"),
    _("website"),
    _("notyet"),
    _("landlord"),
    _("tenant"),
    _("wants_other_listing"),
    _("hobbyroom"),
    _("stockroom"),
    _("workshop"),
    _("assignment_craft"),
    _("rooftop"),
    _("new_tasks_half"),
    _("application_today_half"),
    _("lost_mails_half"),
    _("end_date"),
    _("needs_discussion"),
    _("comment"),
    _("accounting_cleared"),
    _("accounting_date"),
    _("area_rent"),
    _("direct_offer"),
    _("advertisement_end"),
    _("send_mail_craft"),
    _("send_mail_apartment"),
    _("send_mail_other"),
    _("send_mail_virtual"),
    _("send_mail_simple"),
    _("send_mail_parkingspace"),
    _("send_mail_inspection"),
    _("Virtual"),
    _("co_legal_form"),
    _("co_industry"),
    _("co_founding_year"),
    _("isometry"),
    _("situation_plan"),
    _("evaluator_first"),
    _("evaluator_second_evaluator"),
    _("direct_alternatives"),
    _("info_checklist"),
    _("adv_move_in_date"),
    _("rank"),
    _("direct_offer"),
    _("advertisement_end"),
    _("num_acceptance"),
    _("num_applications_prio_1"),
    _("num_rented"),
    _("mittel"),
    _("co_legal_form"),
    _("co_industry"),
    _("co_certificate_of_registration_doc"),
    _("disability_pension"),
    _("prio_1_object"),
    _("deduction_of_tax_at_source"),
    _("income_gross_net"),
    _("child_custody"),
    _("log_rank"),
    _("cp_to_tenant"),
    _("pin_rank"),
    _("relocation_request"),
    _("relocation_request_craft"),
    _("relocation_request_other"),
    _("relocation_request_parking"),
    _("wait_list"),
    _("household_income_input"),
    _("contract_state"),
    _("object_repr"),
    _("loggia"),
    _("swm_recalc"),
    _("reference_number"),
    _("target_group"),
    _("deposit"),
    _("denied_reason"),
    _("car_waiver"),
    _("has_car"),
    _("has_motorcycle"),
    _("has_parking"),
    _("has_parking_detail"),
    _("income_group"),
    _("edit_model"),
    _("delete_model"),
    _("references_landlord_evaluation"),
    _("references_employer_evaluation"),
    _("contact"),
    _("out_rooms"),
    _("out_object_type"),
    _("out_area"),
    _("out_rent"),
    _("co_legal_form"),
    _("co_name"),
    _("co_industry"),
    _("co_certificate_of_registration"),
    _("co_vat"),
    _("co_businessplan_doc"),
    _("present_in_apartment"),
    _("offer_send_mail_user"),
    _("send_waitlist"),
    _("send_mail_parkinspace"),
    _("new_task"),
    _("insurance_agent_template"),
    _("wants_stockroom_detail"),
    _("wants_hobbyroom_detail"),
    _("num_ecars_special"),
    _("lang"),
    _("household_type_detail"),
    _("household_income_net"),
    _("apartment_visited_detail"),
    _("wohnungsnummern"),
    _("zusammenlegen"),
    _("constructional_adaptations_detail"),
    _("freezer"),
    _("engagement_filter"),
    _("constructional_adaptations"),
    _("household_income_net"),
    _("career_change"),
    _("career_change_detail"),
    _("working_since_in_years"),
    _("enforcement_detail "),
    _("commuter_type"),
    _("child_of_parent"),
    _("tender_title"),
    _("loggia_area"),
    _("garden_sitting_place_area"),
    _("rentalprice_squaremeter_net"),
    _("rentalprice_squaremeter"),
    _("terrace_area"),
    _("notice_of_termination_date"),
    _("employment_fixedterm_date"),
    _("employment_fixedterm"),
    _("employment_contract_terminated_date"),
    _("phone_mobile"),
    _("Evaluate marked objects as tenants"),
    _("prerenter"),
    _("curator"),
    _("relocationrequests"),
    _("previous_rooms"),
    _("employment_type"),
    _("company_division"),
    _("temporary_employment"),
    _("company_organisational_unit"),
    _("child_employed"),
    _("Commitment evaluation"),
    _("Mobility evaluation"),
    _("Priority evaluation"),
    _("Acomment evaluation"),
    _("Presentation evaluation"),
    _("Status Application"),
    _("Household evaluation"),
    _("Instrument evaluation"),
    _("Document evaluation"),
    _("Solvency evaluation"),
    _("Urgency evaluation"),
    _("Pets evaluation"),
    _("Urgency evaluation"),
    _("Validity evaluation"),
    _("Document evaluation"),
    _("income_rent_ratio"),
    _("Parking detail"),
    _("parking detail"),
    _("bfs_region"),
    _("without_offers"),
    _("project_reference"),
    _("project_reference_detail"),
    _("project_reference_duration"),
    _("project_reference_since"),
    _("munich_doc"),
    _("social_housing_doc"),
    _("temporary_tenant"),
    _("unobstructed_doc"),
    _("notvacant"),
    _("min_max_rooms_0"),
    _("min_max_rooms_1"),
    _("min_max_miete_0"),
    _("min_max_miete_1"),
    _("min_max_rent_0"),
    _("min_max_rent_1"),
    _("adults_exist"),
    _("children_exist"),
    _("children_gender"),
    _("date_of_event"),
    _("disability_certificate_doc"),
    _("priorities_input"),
    _("social_points"),
    _("urgency_points"),
    _("social_people"),
    _("social_number"),
    _("social_rooms"),
    _("social_validity"),
    _("layout_plan"),
    _("send_mail_to_curator"),
    _("contract_details"),
    _("signed_on"),
    _("year_of_construction"),
    _("relocation_apartment_comment"),
    _("garden"),
    _("disability_pension_quota"),
    _("company_until"),
    _("additional_costs_1"),
    _("additional_costs_2"),
    _("assignment_history"),
    _("erp_apartment"),
    _("incidentals"),
    _("disability_pension_quota"),
    _("disability_pension_quota"),
    _("disability_pension_quota"),
    _("wait_list_min_max_miete"),
    _("wait_list_min_max_rooms"),
    _("paused"),
    _("relocation_reasons"),
    _("proprietor"),
    _("inactive.anonym"),
    _("normal"),
    _("subvention"),
    _("social"),
    _("insurance"),
    _("deposit"),
    _("situation_plan"),
    _("factsheets"),
    _("domicile_same_municipality"),
    _("domicile_same_municipality_detail"),
    _("work_same_municipality"),
    _("work_same_municipality_detail"),
    _("domicile_same_municipality_past"),
    _("domicile_same_municipality_past_detail"),
    _("relatives_same_municipality"),
    _("relatives_same_municipality_detail"),
    _("adult_is_member"),
    _("application_pdf"),
    _("building_publicated_adress"),
    _("building_street"),
    _("factsheets"),
    _("object_select"),
    _("fake_field_for_show_error"),
    _("file"),
    _("object_select_1"),
    _("object_select_2"),
    _("previous_offer_declined"),
    _("securities_detail"),
    _("securities_details"),
    _("timeslots"),
    _("adult_is_member"),
    _("adult_is_member"),
    _("adult_is_member"),
    _("number_of_declining_landlord_old"),
    _("employment_contract_doc"),
    _("passport_doc"),
    _("company_name"),
    _("company_founding_year"),
    _("company_annual_turnover"),
    _("company_contact"),
    _("company_contact_phone"),
    _("company_contact_email"),
    _("current_housing_situation"),
    _("landlord_contact"),
    _("landlord_contact_phone"),
    _("landlord_contact_email"),
    _("current_housing_situation_detail"),
    _("move_three_years"),
    _("previous_street_nr"),
    _("previous_postcode"),
    _("previous_city"),
    _("has_credittrust"),
    _("credittrust_upload"),
    _("income_doc"),
    _("additional_doc_2"),
    _("additional_doc_3"),
    _("agreement_truth"),
    _("parking_regular"),
    _("pets_type"),
    _("securities_provider"),
    _("securities_provider_details"),
    _("source_detail"),
    _("agreement_penalty"),
]


FORM_FIELD_CUSTOM_TRANSLATION = [
    _("bfs_region"),
    _("employer_reference_finished"),
    _("swm"),
    _("income_net"),
    _("income_net_additional"),
    _("income_gross_additional"),
    _("confirmation_information"),
    _("previous_area"),
    _("agreement_data"),
    _("income_rent_ratio"),
    _("parking_detail"),
    _("volunteering"),
    _("volunteering_hours"),
]


def is_snake_case(string):
    # Check if the string contains only lowercase letters, digits, and underscores
    if re.match(r"^[a-z0-9_]+$", string):
        # Check if the string contains an underscore
        if "_" in string:
            return True
    return False


class Command(BaseCommand):
    def handle(self, *args, **options):
        """Handle command."""
        log.info("Start!")
        for key in FORM_FIELD_CUSTOM_TRANSLATION + CUSTOM_TRANSLATION:
            key = str(key)

            try:
                tk = TranslationKey.objects.get(id_name=key)
            except TranslationKey.DoesNotExist:
                log.error(f"Key not found: {key}")
                continue

            if is_snake_case(key):
                tk.snake_name = key

            if not tk.views:
                tk.views = ["custom"]
            elif "custom" not in tk.views:
                tk.views.append("custom")

            try:
                tk.save()
                log.info(f"Updated: {key}")
            except django.db.utils.IntegrityError:
                log.error(f"Duplicate key: {key}")
                continue

        log.info("Done!")
