Первый
This commit is contained in:
82
Translation.java
Normal file
82
Translation.java
Normal file
@ -0,0 +1,82 @@
|
||||
package tools;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import java.sql.*;
|
||||
|
||||
public class Translation {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Translation.class);
|
||||
|
||||
public int language_id;
|
||||
//public NamedParameterJdbcTemplate jdbcTemplate;
|
||||
public Connection conn;
|
||||
public Translation(String lng, Connection conn){
|
||||
language_id=1;
|
||||
switch (lng) {
|
||||
case "kz":
|
||||
case "kk":
|
||||
language_id = 2;
|
||||
break;
|
||||
case "en":
|
||||
language_id = 3;
|
||||
break;
|
||||
case "uz":
|
||||
language_id = 4;
|
||||
break;
|
||||
case "ru":
|
||||
default:
|
||||
language_id = 1;
|
||||
break;
|
||||
}
|
||||
this.conn = conn;
|
||||
}
|
||||
|
||||
public String trt(String text){
|
||||
|
||||
boolean find = false;
|
||||
String sql = """
|
||||
select
|
||||
translation
|
||||
from
|
||||
main._translations
|
||||
where
|
||||
del=false
|
||||
and language_id=${language_id}
|
||||
and identifier=${identifier};
|
||||
""";
|
||||
|
||||
PreparedStatementNamed stmtn=null;
|
||||
try {
|
||||
stmtn = new PreparedStatementNamed(conn, sql);
|
||||
stmtn.setInt("language_id", language_id);
|
||||
stmtn.setString("identifier", text);
|
||||
} catch (SQLException e) {
|
||||
logger.error("Error",e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(stmtn!=null){
|
||||
PreparedStatement stmt=stmtn.getPreparedStatement();
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
text = rs.getString(1);
|
||||
find = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
logger.error("Error",e);
|
||||
e.printStackTrace();
|
||||
}finally{
|
||||
try { if (rs != null) rs.close(); } catch (Exception e) {};
|
||||
try { if (stmt != null) stmt.close(); } catch (Exception e) {};
|
||||
}
|
||||
}
|
||||
|
||||
if(!find){
|
||||
text = text.replace("_", " ");
|
||||
}
|
||||
return text;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user