2024-07-30 07:46:33 -03:00
|
|
|
import pandas as pd
|
|
|
|
import os
|
2024-09-27 11:08:13 -03:00
|
|
|
import PyLibrary.funciones_comunes as fc
|
2024-07-30 07:46:33 -03:00
|
|
|
|
2024-10-08 11:58:04 -03:00
|
|
|
|
2024-09-19 04:05:19 -03:00
|
|
|
def exportar_para_traduccion(tipo_PLC, archivo_maestro, target_lang_code):
|
2024-07-30 07:46:33 -03:00
|
|
|
if not os.path.exists(archivo_maestro):
|
|
|
|
print("El archivo maestro no existe.")
|
|
|
|
return
|
|
|
|
|
2024-10-08 11:58:04 -03:00
|
|
|
# Leer el archivo maestro
|
|
|
|
df_maestro = fc.read_dataframe_with_cleanup_retries(archivo_maestro)
|
2024-07-30 07:46:33 -03:00
|
|
|
|
|
|
|
# Crear un nuevo DataFrame para la exportación
|
|
|
|
df_export = pd.DataFrame()
|
|
|
|
|
2024-10-08 11:58:04 -03:00
|
|
|
# Copiar la primera columna y la columna del idioma de destino
|
|
|
|
primera_columna = df_maestro.columns[0]
|
|
|
|
df_export[primera_columna] = df_maestro[primera_columna]
|
2024-08-01 08:53:38 -03:00
|
|
|
df_export[target_lang_code] = df_maestro[target_lang_code]
|
2024-07-30 07:46:33 -03:00
|
|
|
|
|
|
|
# Guardar el archivo exportado
|
2024-09-19 04:05:19 -03:00
|
|
|
ruta_export = os.path.join(os.path.dirname(archivo_maestro), f'2_master_export2translate_{tipo_PLC}.xlsx')
|
2024-10-08 11:58:04 -03:00
|
|
|
|
|
|
|
# Usar ExcelWriter para tener más control sobre el proceso de escritura
|
|
|
|
with pd.ExcelWriter(ruta_export, engine='openpyxl') as writer:
|
|
|
|
df_export.to_excel(writer, index=False, sheet_name='Sheet1')
|
|
|
|
|
|
|
|
# Ajustar el ancho de las columnas
|
|
|
|
worksheet = writer.sheets['Sheet1']
|
|
|
|
for idx, col in enumerate(df_export.columns):
|
|
|
|
max_length = max(df_export[col].astype(str).map(len).max(), len(col))
|
|
|
|
if max_length > 50 : max_length = 50
|
|
|
|
worksheet.column_dimensions[chr(65 + idx)].width = max_length + 2
|
2024-08-01 08:53:38 -03:00
|
|
|
|
2024-07-30 07:46:33 -03:00
|
|
|
print(f"Archivo exportado para traducción: {ruta_export}")
|
|
|
|
|
2024-09-19 15:55:58 -03:00
|
|
|
def run(tipo_PLC, codigo_columna_maestra, seleccion_idioma):
|
2024-09-19 04:05:19 -03:00
|
|
|
archivo_maestro = f".\\data\\1_hmi_master_translates_{tipo_PLC}.xlsx"
|
2024-08-01 08:53:38 -03:00
|
|
|
if seleccion_idioma not in fc.IDIOMAS:
|
|
|
|
print("Selección inválida.")
|
|
|
|
else:
|
|
|
|
_, target_lang_code = fc.IDIOMAS[seleccion_idioma]
|
2024-09-19 04:05:19 -03:00
|
|
|
exportar_para_traduccion(tipo_PLC, archivo_maestro, target_lang_code)
|
2024-08-01 12:57:04 -03:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2024-09-19 04:05:19 -03:00
|
|
|
tipo_PLC = "siemens"
|
|
|
|
codigo_columna_maestra = "it-IT"
|
2024-08-01 12:57:04 -03:00
|
|
|
fc.mostrar_idiomas()
|
|
|
|
seleccion_idioma = int(input("Introduce el número del idioma de destino: "))
|
2024-10-08 11:58:04 -03:00
|
|
|
run(tipo_PLC, codigo_columna_maestra, seleccion_idioma)
|