const english_base = {
    "extensionName":"",
    "extDesc":"",
    "OpenSidebar":"",
    "button_new":"",
    "button_pin":"",
    "button_undo":"",
    "button_reboot":"",
    "button_detach":"",
    "button_move":"",
    "button_search":"",
    "button_tools":"",
    "button_groups":"",
    "filter_search_go_prev":"",
    "filter_search_go_next":"",
    "button_bookmarks":"",
    "button_downloads":"",
    "button_history":"",
    "button_settings":"",
    "button_options":"",
    "button_extensions":"",
    "button_unload":"",
    "button_discard":"",
    "button_filter_type":"",
    "button_groups_toolbar_hide":"",
    "button_new_group":"",
    "button_remove_group":"",
    "button_edit_group":"",
    "button_import_group":"",
    "button_export_group":"",
    "button_backup":"",
    "button_import_bak":"",
    "button_import_merge_bak":"",
    "button_export_bak":"",
    "button_load_bak1":"",
    "button_load_bak2":"",
    "button_load_bak3":"",
    "button_folders":"",
    "button_new_folder":"",
    "button_remove_folder":"",
    "button_edit_folder":"",
    "menu_expand_all":"",
    "menu_collapse_all":"",
    "menu_expand_tree":"",
    "menu_collapse_tree":"",
    "menu_new_tab":"",
    "menu_new_pin":"",
    "menu_duplicate_tab":"",
    "menu_detach_tab":"",
    "menu_reload_tab":"",
    "menu_pin_tab":"",
    "menu_mute_tab":"",
    "menu_mute_tree":"",
    "menu_unmute_tree":"",
    "menu_unmute_tab":"",
    "menu_mute_other":"",
    "menu_unmute_other":"",
    "menu_unpin_tab":"",
    "menu_close_tree":"",
    "menu_close":"",
    "menu_close_other":"",
    "menu_undo_close_tab":"",
    "menu_treetabs_settings":"",
    "menu_unload":"",
    "menu_bookmark_tree":"",
    "menu_new_folder":"",
    "menu_rename_folder":"",
    "menu_delete_folder":"",
    "menu_new_group":"",
    "menu_rename_group":"",
    "menu_delete_group":"",
    "menu_delete_group_tabs_close":"",
    "menu_groups_unload":"",
    "menu_bookmark_group":"",
    "menu_groups_hibernate":"",
    "menu_group_tabs_close":"",
    "status_bar_rearranging_tabs":"",
    "status_bar_rearranging_finished":"",
    "status_bar_loaded_tree_structure":"",
    "status_bar_finding_ref_tabs":"",
    "status_bar_finding_other_windows":"",
    "status_bar_all_done":"",
    "status_bar_autosave":"",
    "status_bar_quick_check_recreate_structure":"",
    "options_vivaldi":"",
    "opt_url_for_web_panel":"",
    "options_pinned":"",
    "options_pin_list_multi_row":"",
    "option_allow_pin_close":"",
    "option_pin_attention_blinking":"",
    "option_audio_blinking":"",
    "options_tabs":"",
    "options_syncro_tabbar_tabs_order":"",
    "options_switch_with_scroll":"",
    "options_tab_group_regex":"",
    "option_tab_match":"",
    "option_tab_group":"",
    "options_orphaned_tabs_to_ungrouped":"",
    "options_move_on_url_change":"",
    "options_move_on_url_change_never":"",
    "options_move_on_url_change_from_empty":"",
    "options_move_on_url_change_from_empty_b":"",
    "options_move_on_url_change_all_new":"",
    "options_move_on_url_change_always":"",
    "options_always_show_close":"",
    "options_never_show_close":"",
    "options_collapse_other_trees":"",
    "options_open_tree_on_hover":"",
    "options_promote_children":"",
    "options_promote_children_in_first_child":"",
    "options_skip_load":"",
    "options_midclick_tab":"",
    "options_dbclick_tab":"",
    "options_action_tab_none":"",
    "options_action_tab_new":"",
    "options_action_tab_expand_collapse":"",
    "options_action_tab_close":"",
    "options_action_tab_reload":"",
    "options_action_tab_unload":"",
    "options_action_tab_activate_previous_active":"",
    "options_action_tab_undo_close":"",
    "options_midclick_group":"",
    "options_dbclick_group":"",
    "options_action_group_none":"",
    "options_action_group_new":"",
    "options_action_group_activate_previous_active":"",
    "options_action_group_undo_close_tab":"",
    "options_append_pinned_tab":"",
    "options_append_pinned_tab_first":"",
    "options_append_pinned_tab_after":"",
    "options_append_pinned_tab_last":"",
    "options_append_child_tab":"",
    "options_append_child_tab_top":"",
    "options_append_child_tab_bottom":"",
    "options_append_child_tab_after":"",
    "options_append_orphan_tab":"",
    "options_append_orphan_tab_top":"",
    "options_append_orphan_tab_after_active":"",
    "options_append_orphan_tab_bottom":"",
    "options_append_orphan_tab_as_child":"",
    "options_append_orphan_tab_active_parent_top":"",
    "options_append_orphan_tab_active_parent_bottom":"",
    "options_toolbar_new_tab":"",
    "options_toolbar_new_tab_as_regular_orphan":"",
    "options_toolbar_new_tab_root_of_group":"",
    "options_after_closing_active_tab":"",
    "options_after_closing_active_tab_go_up":"",
    "options_after_closing_active_tab_go_down":"",
    "options_after_closing_active_tab_go_up_seek_in_parent":"",
    "options_after_closing_active_tab_go_down_seek_in_parent":"",
    "options_after_closing_active_tab_go_browser":"",
    "options_append_child_tab_after_limit":"",
    "options_append_child_tab_after_limit_top":"",
    "options_append_child_tab_after_limit_after":"",
    "options_append_child_tab_after_limit_bottom":"",
    "options_show_counter_tabs":"",
    "options_show_counter_tabs_hints":"",
    "options_max_tree_depth":"",
    "options_max_tree_drag_drop":"",
    "options_groups":"",
    "options_show_counter_groups":"",
    "options_groups_toolbar_default":"",
    "options_syncro_tabbar_groups_tabs_order":"",
    "options_hide_other_groups_tabs_firefox":"",
    "options_folders":"",
    "options_midclick_folder":"",
    "options_dbclick_folder":"",
    "options_action_folder_none":"",
    "options_action_folder_rename":"",
    "options_action_folder_new_folder":"",
    "options_action_folder_new_tab":"",
    "options_action_folder_expand_collapse":"",
    "options_action_folder_close":"",
    "options_action_folder_unload":"",
    "options_global":"",
    "options_theme":"",
    "options_rename_theme_button":"",
    "options_add_theme_button":"",
    "options_remove_theme_button":"",
    "options_import_theme_button":"",
    "options_export_theme_button":"",
    "options_share_theme_link":"",
    "options_toolbar":"",
    "options_available_buttons":"",
    "options_reset_toolbar_button":"",
    "options_export_debug":"",
    "options_print_debug":"",
    "options_toolbar_look":"",
    "hint_orphan_tab":"",
    "hint_ctrl_t":"",
    "hint_from_pin":"",
    "hint_from_bookmark":"",
    "hint_from_external_link":"",
    "hint_from_popup":"",
    "hint_explained_new_tab_settings":"",
    "hint_explained_orphan_after_active_settings":"",
    "button_background":"",
    "button_hover_background":"",
    "button_on_background":"",
    "button_icons":"",
    "button_icons_hover":"",
    "button_on_icons":"",
    "button_border":"",
    "button_hover_border":"",
    "filter_box_font":"",
    "filter_box_background":"",
    "filter_box_border":"",
    "filter_clear_icon":"",
    "toolbar_background":"",
    "toolbar_shelf_background":"",
    "toolbar_border_bottom":"",
    "button_shelf_background":"",
    "button_shelf_hover_background":"",
    "button_shelf_icons":"",
    "button_shelf_icons_hover":"",
    "button_shelf_border":"",
    "button_shelf_hover_border":"",
    "options_theme_tabs":"",
    "options_tabs_margin_overlap":"",
    "options_tabs_margin_0":"",
    "options_tabs_margin_1":"",
    "options_tab_list_scrollbar_width_down":"",
    "options_tab_list_scrollbar_width_up":"",
    "options_tab_list_scrollbar_height_down":"",
    "options_tab_list_scrollbar_height_up":"",
    "options_tabs_indentation_down":"",
    "options_tabs_indentation_up":"",
    "options_tabs_roundness_down":"",
    "options_tabs_roundness_up":"",
    "options_tabs_size_down":"",
    "options_tabs_size_up":"",
    "options_theme_tabs_sample_text_normal":"",
    "options_theme_tabs_sample_text_normal_hover":"",
    "options_theme_tabs_sample_text_normal_selected":"",
    "options_theme_tabs_sample_text_normal_selected_hover":"",
    "options_theme_tabs_sample_text_active":"",
    "options_theme_tabs_sample_text_active_hover":"",
    "options_theme_tabs_sample_text_active_selected":"",
    "options_theme_tabs_sample_text_active_selected_hover":"",
    "options_theme_tabs_sample_text_discarded":"",
    "options_theme_tabs_sample_text_discarded_hover":"",
    "options_theme_tabs_sample_text_discarded_selected":"",
    "options_theme_tabs_sample_text_discarded_selected_hover":"",
    "options_theme_tabs_sample_text_search_result":"",
    "options_theme_tabs_sample_text_search_result_hover":"",
    "options_theme_tabs_sample_text_search_result_active":"",
    "options_theme_tabs_sample_text_search_result_active_hover":"",
    "options_theme_tabs_sample_text_search_result_selected":"",
    "options_theme_tabs_sample_text_search_result_selected_hover":"",
    "options_theme_tabs_sample_text_search_result_selected_active":"",
    "options_theme_tabs_sample_text_search_result_selected_active_hover":"",
    "options_theme_tabs_sample_text_search_result_highlighted":"",
    "options_theme_tabs_sample_text_search_result_highlighted_hover":"",
    "options_theme_tabs_sample_text_search_result_highlighted_active":"",
    "options_theme_tabs_sample_text_search_result_highlighted_active_hover":"",
    "options_theme_tabs_sample_text_search_result_highlighted_selected":"",
    "options_theme_tabs_sample_text_search_result_highlighted_selected_hover":"",
    "options_theme_tabs_sample_text_search_result_highlighted_selected_active":"",
    "options_theme_tabs_sample_text_search_result_highlighted_selected_active_hover":"",
    "attention_background":"",
    "attention_border":"",
    "pin_list_border_bottom":"",
    "pin_list_background":"",
    "folder_icon_open":"",
    "folder_icon_closed":"",
    "folder_icon_hover":"",
    "expand_open_background":"",
    "expand_closed_background":"",
    "expand_hover_background":"",
    "group_list_button_hover_background":"",
    "group_list_borders":"",
    "group_list_default_font_color":"",
    "group_list_background":"",
    "tab_list_background":"",
    "drag_indicator":"",
    "close_x":"",
    "close_hover_x":"",
    "close_hover_border":"",
    "close_hover_background":"",
    "scrollbar_thumb":"",
    "scrollbar_thumb_hover":"",
    "scrollbar_track":"",
    "options_example_menu_item":"",
    "options_menu":"",
    "tabs_menu_hover_border":"",
    "tabs_menu_hover_background":"",
    "tabs_menu_separator":"",
    "tabs_menu_font":"",
    "tabs_menu_border":"",
    "tabs_menu_background":"",
    "options_there_is_a_theme_with_this_name":"",
    "options_theme_name_cannot_be_empty":"",
    "options_no_theme_to_export":"",
    "options_loaded_theme_older_version":"",
    "options_loaded_theme_newer_version":"",
    "options_vivaldi_copied_url":"",
    "options_copied_wallet_address":"",
    "options_clear_data":"",
    "options_development":"",
    "options_debug":"",
    "group_edit_button_cancel":"",
    "group_edit_button_confirm":"",
    "folder_edit_button_cancel":"",
    "folder_edit_button_confirm":"",
    "manager_window_button_label_import_group":"",
    "manager_window_button_label_import_session":"",
    "manager_window_button_label_save_current_session":"",
    "caption_ungrouped_group":"",
    "caption_noname_group":"",
    "caption_clear_filter":"",
    "caption_loading":"",
    "caption_searchbox":"",
    "manager_window_header_title":"",
    "menu_manager_window":"",
    "button_manager_window":"",
    "manager_window_groups_button":"",
    "manager_window_sessions_button":"",
    "manager_window_autosave_button":"",
    "manager_window_button_label_hibernate_group":"",
    "manager_window_autosessions_maximum_saves_label":"",
    "manager_window_autosessions_save_timer_label":"",
    "manager_window_delete_icon":"",
    "manager_window_savetofile_icon":"",
    "manager_window_merge_icon":"",
    "manager_window_load_icon":"",
    "options_Remove_button":"",
    "add_tab_group_regex":"",
    "menu_unload_tree":"",
    "status_bar_running_in_safe_mode":"",
    "status_bar_ready":""
};

let translator = {

  Nodes: {
  },
  init: function() {
    for (var Id in english_base) {
      translator.Nodes[Id] = new translator.textBox({id: Id, message: english_base[Id].message});
    }
    document.getElementById("load_translation").onclick = function(event) {
      if (event.which == 1) {
        translator.File.OpenFile(); 
      }
    }
    document.getElementById("export_translation").onclick = function(event) {
      if (event.which == 1) {
        translator.File.SaveFile(); 
      }
    }
    
  },
  textBox: class {
    constructor(p) {
        let textValue = chrome.i18n.getMessage(p.id);
        let OriginalText = document.createElement("div");
        OriginalText.classList = "original";
        OriginalText.id = p.id;
        OriginalText.innerHTML = textValue;
        body.appendChild(OriginalText);
        this.OriginalText = OriginalText;
        let TextBox = document.createElement("textarea");
        TextBox.classList = "translated";
        TextBox.id = p.id;
        TextBox.style.width = "100%";
        TextBox.value = textValue;
        TextBox.style.whiteSpace = "normal";
        TextBox.style.marginBottom = "10px";
        body.appendChild(TextBox);
        this.TextBox = TextBox;
    }
  },
  File: {
    OpenFile: function(extension) {
        let body = document.getElementById("body");
        let inp = document.createElement("input");
        inp.id = "file_import";
        inp.type = "file";
        inp.accept = extension;
        inp.style.display = "none";
        body.appendChild(inp);
        inp.click();

        inp.onchange = function(event) {
          let fr = new FileReader();
          if (inp.files[0] == undefined) return;
          fr.readAsText(inp.files[0]);
          fr.onload = function() {
              let data = JSON.parse(fr.result);
              inp.parentNode.removeChild(inp);
              for (var Id in data) {
                if (translator.Nodes[Id]) {
                  translator.Nodes[Id].TextBox.value = data[Id].message;
                }
              }
          }
        }
    },
    SaveFile: function() {
        let data = {};
        for (var Id in translator.Nodes) {
           data[Id] = {"message": translator.Nodes[Id].TextBox.value};
        }
        let file = new File([JSON.stringify(data)], "messages.json", {type: "text/json;charset=utf-8"});
        let body = document.getElementById("body");
        let savelink = document.createElement("a");
        savelink.href = URL.createObjectURL(file);
        savelink.fileSize = file.size;
        savelink.target = "_blank";
        savelink.style.display = "none";
        savelink.type = "file";
        savelink.download = "messages.json";
        body.appendChild(savelink);
        setTimeout(function() {
            savelink.click();
            setTimeout(function() {
                savelink.parentNode.removeChild(savelink);
            }, 60000);
        }, 10);
    }
  },
}



translator.init();

