@OptIn(ExperimentalMaterial3Api::class)
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
TranslationTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
val enKoTranslator = remember {
val options = TranslatorOptions.Builder()
.setSourceLanguage(TranslateLanguage.ENGLISH)
.setTargetLanguage(TranslateLanguage.KOREAN)
.build()
Translation.getClient(options)
}
var enabled by remember {
mutableStateOf(false)
}
LaunchedEffect(Unit) {
val conditions = DownloadConditions.Builder()
.requireWifi()
.build()
enKoTranslator.downloadModelIfNeeded(conditions)
.addOnSuccessListener {
enabled = true
}
.addOnFailureListener { exception ->
}
}
var textEn by remember { mutableStateOf("") }
var textTranslated by remember { mutableStateOf("") }
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(
text = "퀄리티 높은 무료 번역",
fontWeight = FontWeight.Bold,
fontSize = 20.sp,
modifier = Modifier
.padding(20.dp)
.align(Alignment.CenterHorizontally)
)
Box(
modifier = Modifier
.background(color = Color.LightGray)
.fillMaxWidth()
)
TextField(
value = textEn,
onValueChange = { textEn = it },
label = { Text(text = "번역할 내용을 입력하세요.") },
placeholder = { Text(text = "") },
maxLines = 10,
textStyle = TextStyle(color = Color.Black),
modifier = Modifier
.padding(30.dp)
.height(180.dp)
.fillMaxWidth()
)
Spacer(
modifier = Modifier
.size(20.dp)
)
Button(
onClick = {
enKoTranslator.translate(textEn)
.addOnSuccessListener { translatedText ->
textTranslated = translatedText
}
.addOnFailureListener { exception ->
}
},
enabled = enabled,
colors = ButtonDefaults.buttonColors(
containerColor = Color(0xff4B5F93),
contentColor = Color.White
),
) {
Text(text = "Translate")
}
Spacer(
modifier = Modifier
.size(30.dp)
)
Box(
modifier = Modifier
.background(color = Color(0xffE1E2EC))
.width(320.dp)
.height(250.dp)
.padding(5.dp)
) {
Column {
Text(text = "번역 결과", color = Color.Gray, fontSize = 15.sp)
Text(text = "$textTranslated")
}
}
Spacer(
modifier = Modifier
.padding(10.dp)
)
Image(
painter = painterResource(id = R.drawable.ad),
contentDescription = null
)
}
}
}
}
}
}
퀄리티 높은 무료 번역 앱이지만 사실 완전 저퀄리티지롱