#!/usr/bin/env python
# coding:utf-8

import os
import sys

curr_dir = os.path.split(os.path.abspath(__file__))[0]
print("curr_dir = " + curr_dir)
sys.path.append(os.path.join(curr_dir, "../"))
sys.path.append(os.path.join(curr_dir, "../google_drive"))

from google_drive.google_sheet import GoogleSheetHelper

"""
多语言表格读取类
"""
class multilingual_table:
    def __init__(self, sheet_file_name, sheet_table_name):
        sheet_helper = GoogleSheetHelper()
        sheet = sheet_helper.get_sheet_table(sheet_file_name, sheet_table_name)
        sheet_datas = sheet.get_all_values(major_dimension='ROWS')
        self.multi_col_dict = {}
        self.multi_language_dict = {}

        for i, row_values in enumerate(sheet_datas):
            row = i + 1
            if row < 3:
                continue
            if row == 3:
                for j, cell_value in enumerate(row_values):
                    col = j + 1
                    self.multi_col_dict[col] = cell_value
            if row > 3:
                key = row_values[0]
                language_item_dict = {}
                for j, cell_value in enumerate(row_values):
                    if j == 0:
                        continue
                    col = j + 1
                    language_item_dict[self.multi_col_dict[col]] = cell_value
                self.multi_language_dict[key] = language_item_dict


    def get_language_item(self, key):
        if key in self.multi_language_dict:
            return self.multi_language_dict[key]
        return None

    def get_item_language_value(self, key, language):
        language_item = self.get_language_item(key)
        if language_item is None:
            return ""
        if language in language_item:
            return language_item[language]
        return ""

if __name__ == '__main__':
    multi = multilingual_table("AI Localization FindObject", "_gen_play_type")
    print(multi.get_language_item("thesmiths"))
