I have the following queries.
$language = Language::where('code', $from)->first();
$languageTranslated = Language::where('code', $to)->first();
$ids = TermTranslation::select('id')->where("language_id", $language->id)->get();
$remainIds = TermTranslation::select('id')->where("language_id", $languageTranslated->id)->whereNotIn('term_id', $ids)->get();
return $remainIds;
I have the following requirements, I want to get how many terms are not being translated from language(en) to language(fr) (languages could change). So I'm running the above query that is taking a lot of time. So what could be better way?
Once I get the remaining ids of terms, which are not translated, I need to check how many words available in those terms, then I'm trying to count words as.
$language = Language::where('code', $from)->first();
$totalWords = 0;
$remainTermIds = $this->getFromTermRemainIds($from, $to);
$termNames = TermTranslation::where("language_id", $language->id)->whereIn('term_id', $remainTermIds)->get();
$termNotes = TermNoteTranslation::where("language_id", $language->id)->whereIn('term_id', $remainTermIds)->get();
foreach ($termNames as $termName) {
foreach (explode(' ', $termName->name) as $name) {
if (strlen($name) > 2) {
$totalWords += 1;
}
}
}
foreach ($termNotes as $termNote) {
foreach (explode(' ', strip_tags($termNote->note)) as $note) {
if (strlen($note) > 2) {
$totalWords += 1;
}
}
}
return $totalWords;
So any better solution for these two requirements?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire