How to roughly and automatically translate database contents once?

Let's say there is a very large SQL database - hundreds of tables, thousands of fields, millions of records. This database is in Dutch. I would like to translate all the values ​​of certain fields for testing purposes in English. It does not have to be completely correct, it must be readable by testers.

I know that most texts are stored in fields called "name" and "description" throughout the database. Or basically all fields of type NVARCHAR (any length) in all tables will be candidates for translation. Enumerating all the tables and fields is really too much, and I would like to avoid this, so translating only these fields would be enough.

Is there a way to go through all the tables and for all records to extract values ​​from certain fields and replace them with English translations? Can this only be done with SQL?

The db server does not matter - I can mount the database on MSSQL, Oracle or any server of my choice. Translation of texts using Google or some other automatic tool is good enough for this purpose. Of course, this tool must have an API for automatic use.

Does anyone have experience with such operations?

+3
source share
1 answer

In Pseudocode, here is what I would like to do using Oracle:

Query AllFieldsQuery = new Query(connection,"Select table_name, column_name 
from user_tab_columns where column_name='name' OR column_name='description'");

AllFieldsQuery.ExecuteReader();

It gives you something like this:

TABLE_NAME | COLUMN_NAME

Table1 | Name

Table2 | Name

Table2 | Description

........... |...........

Foreach TableColumnLine

Query FieldQuery = new Query("Select DISTINCT "+COLUMN_NAME+" AS ToTranslate 
from +"TABLE_NAME);

Create a new parametrized query :
MyParamQuery = new ParamQuery(connection, UPDATE TABLE_NAME SET COLUMN_NAME =
@Translated WHERE COLUMN_NAME = @ToTranslate);

Foreach ToTranslateLine

@Translated = GetTranslationFromGoogle(@ToTranslate);

MyParamQuery.Execute(ToTranslate = @ToTranslate, Translated = @Translated);

End Foreach ToTranslateLine

End Foreach TableColumnLine

AllFieldsQuery , .

FieldQuery , .

MyParamQuery .

, , . , , , API , / .

.

: sql.

, , , , , UPDATES sql, , , , SQL.

.

:

API , , , SQL .

+3

Source: https://habr.com/ru/post/1782312/


All Articles