Strojno prevajanje konceptov, manjši popravki
parent
9d50577f51
commit
9dc26007a0
|
@ -42,6 +42,9 @@
|
||||||
*.xml text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
|
*.xml text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
|
||||||
*.yml text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
|
*.yml text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
|
||||||
|
|
||||||
|
# PHPStan's baseline uses tabs instead of spaces.
|
||||||
|
core/.phpstan-baseline.php text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tabwidth=2 diff=php linguist-language=php
|
||||||
|
|
||||||
# Define binary file attributes.
|
# Define binary file attributes.
|
||||||
# - Do not treat them as text.
|
# - Do not treat them as text.
|
||||||
# - Include binary diff in patches instead of "binary files differ."
|
# - Include binary diff in patches instead of "binary files differ."
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -42,7 +42,7 @@ const urediPojem = async () => {
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// Prazen pojem? Nazaj na manifest
|
// Prazen pojem? Nazaj na manifest
|
||||||
if (!pojem.value.id) {
|
if ((!pojem.value || !pojem.value.id) && store.pojmi) {
|
||||||
navigateTo('/manifest#skrol')
|
navigateTo('/manifest#skrol')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
{
|
{
|
||||||
"jugofuturizem": "jugofuturizem"
|
"domov": "domov",
|
||||||
|
"Dodaj nov pojem": "Dodaj nov pojem",
|
||||||
|
"Uredi": "Uredi",
|
||||||
|
"jugofuturizem": "jugofuturizem",
|
||||||
|
"manifest": "manifest",
|
||||||
|
"Vsak lahko prispeva k vsebinam manifesta. Predlaga lahko nov pojem ali ureja, dopolni ali predela obstoječe.": "Vsak lahko prispeva k vsebinam manifesta. Predlaga lahko nov pojem ali ureja, dopolni ali predela obstoječe."
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
import { defineNuxtModule } from '@nuxt/kit'
|
import { defineNuxtModule, extendPages } from '@nuxt/kit'
|
||||||
|
|
||||||
export default defineNuxtModule({
|
export default defineNuxtModule({
|
||||||
setup(moduleOptions, nuxt) {
|
setup(moduleOptions, nuxt) {
|
||||||
nuxt.hook('pages:extend', pages => {
|
extendPages((pages) => {
|
||||||
pages.push({
|
pages.push({
|
||||||
name: 'pojem_poglej',
|
name: 'pojem_poglej',
|
||||||
path: '/manifest/:naslov',
|
path: '/manifest/:naslov',
|
||||||
file: '~/pages/manifest/pojem.vue'
|
file: '../../pages/manifest/pojem.vue'
|
||||||
}, {
|
}, {
|
||||||
name: 'pojem_uredi',
|
name: 'pojem_uredi',
|
||||||
path: '/manifest/:naslov/uredi/:guid',
|
path: '/manifest/:naslov/uredi/:guid',
|
||||||
file: '~/pages/manifest/pojem.vue'
|
file: '../../pages/manifest/pojem.vue'
|
||||||
}, {
|
}, {
|
||||||
name: 'pojem_dodaj',
|
name: 'pojem_dodaj',
|
||||||
path: '/manifest/dodaj/:guid',
|
path: '/manifest/dodaj/:guid',
|
||||||
file: '~/pages/manifest/dodaj.vue'
|
file: '../../pages/manifest/dodaj.vue'
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
|
"module": true,
|
||||||
|
"main": "app.vue",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "nuxt build",
|
"build": "nuxt build",
|
||||||
"dev": "nuxt dev",
|
"dev": "nuxt dev",
|
||||||
|
|
|
@ -47,7 +47,7 @@ class Client {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Poizvedi na etherpadov API. Doda baseURL in verzijo pred zeljen url, doda
|
* Poizvedi na etherpadov API. Doda baseURL in verzijo pred zeljen url, doda
|
||||||
* API ključ in uredi parametre. Vendo je POST!
|
* API ključ in uredi parametre. Vedno je POST!
|
||||||
*/
|
*/
|
||||||
public function request($url, $opts = []) {
|
public function request($url, $opts = []) {
|
||||||
$uri = "{$this->baseUrl}/" . self::API_VERSION . '/' . explode('?', $url)[0];
|
$uri = "{$this->baseUrl}/" . self::API_VERSION . '/' . explode('?', $url)[0];
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
use Drupal\Core\Entity\EntityInterface;
|
||||||
use Drupal\node\NodeInterface;
|
use Drupal\node\NodeInterface;
|
||||||
|
use Drupal\Core\Site\Settings;
|
||||||
|
use Symfony\Component\HttpClient\HttpClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file
|
* @file
|
||||||
|
@ -14,6 +15,7 @@ use Drupal\node\NodeInterface;
|
||||||
*/
|
*/
|
||||||
function yufu_concept_node_presave(EntityInterface $entity) {
|
function yufu_concept_node_presave(EntityInterface $entity) {
|
||||||
if ($entity instanceOf NodeInterface && $entity->bundle() == 'concept') {
|
if ($entity instanceOf NodeInterface && $entity->bundle() == 'concept') {
|
||||||
|
// Dodaj avtorja spremembe med urednike, če še ni
|
||||||
$transition = \Drupal::service('content_moderation_notifications.notification_information')->getTransition($entity);
|
$transition = \Drupal::service('content_moderation_notifications.notification_information')->getTransition($entity);
|
||||||
if ($transition->id() == 'publish') {
|
if ($transition->id() == 'publish') {
|
||||||
if ($user = $entity->uid->entity) {
|
if ($user = $entity->uid->entity) {
|
||||||
|
@ -26,3 +28,69 @@ function yufu_concept_node_presave(EntityInterface $entity) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dodaj oz. posodobi manjkajoce prevode (ampak samo ce ne gre za
|
||||||
|
// strojni prevod!)
|
||||||
|
function yufu_concept_node_insert(EntityInterface $entity) {
|
||||||
|
uskladi_prevode($entity);
|
||||||
|
}
|
||||||
|
function yufu_concept_node_update(EntityInterface $entity) {
|
||||||
|
uskladi_prevode($entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
function prevedi_koncept(EntityInterface $entity, EntityInterface $prevod) {
|
||||||
|
$libretranslate = \Drupal::service('yufu_concept.translate');
|
||||||
|
|
||||||
|
$izvorniJezik = $entity->language()->getId();
|
||||||
|
$ciljniJezik = $prevod->language()->getId();
|
||||||
|
|
||||||
|
[$naslov, $tekst] = $libretranslate->prevedi([
|
||||||
|
$entity->title->value,
|
||||||
|
$entity->body->value
|
||||||
|
], $izvorniJezik, $ciljniJezik);
|
||||||
|
|
||||||
|
// Cirilica v latinico
|
||||||
|
if ($ciljniJezik == 'sr') {
|
||||||
|
[$naslov, $tekst] = array_map(function ($tekst) {
|
||||||
|
return transliterator_transliterate('Russian-Latin/BGN', $tekst);
|
||||||
|
}, [$naslov, $tekst]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$prevod->set('title', $naslov);
|
||||||
|
$prevod->set('body', $tekst);
|
||||||
|
}
|
||||||
|
|
||||||
|
function uskladi_prevode(EntityInterface $entity) {
|
||||||
|
if ($entity instanceOf NodeInterface
|
||||||
|
&& $entity->bundle() == 'concept'
|
||||||
|
&& !$entity->field_strojni_prevod->value) {
|
||||||
|
|
||||||
|
$vsiJeziki = array_keys(\Drupal::languageManager()->getLanguages());
|
||||||
|
|
||||||
|
// Katere prevode koncepta že imamo?
|
||||||
|
$izvorniJezik = $entity->language()->getId();
|
||||||
|
$jezikiKoncepta = array_keys($entity->getTranslationLanguages());
|
||||||
|
$ostaliJeziki = array_diff($vsiJeziki, [$izvorniJezik]);
|
||||||
|
|
||||||
|
// Dodamo nove prevode, če je treba
|
||||||
|
$manjkajoci = array_diff($vsiJeziki, $jezikiKoncepta);
|
||||||
|
foreach($manjkajoci as $jezik) {
|
||||||
|
$prevod = $entity->addTranslation($jezik, $entity->toArray());
|
||||||
|
prevedi_koncept($entity, $prevod);
|
||||||
|
$prevod->set('field_strojni_prevod', true);
|
||||||
|
$prevod->save();
|
||||||
|
|
||||||
|
$ostaliJeziki = array_diff($ostaliJeziki, [$jezik]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Posodobimo obstoječe prevode, če so strojni
|
||||||
|
$entityRepository = \Drupal::service('entity.repository');
|
||||||
|
foreach($ostaliJeziki as $jezik) {
|
||||||
|
$prevod = $entityRepository->getTranslationFromContext($entity, $jezik);
|
||||||
|
if ($prevod->field_strojni_prevod) {
|
||||||
|
prevedi_koncept($entity, $prevod);
|
||||||
|
$prevod->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,3 +3,7 @@ services:
|
||||||
class: Drupal\Core\Logger\LoggerChannel
|
class: Drupal\Core\Logger\LoggerChannel
|
||||||
factory: logger.factory:get
|
factory: logger.factory:get
|
||||||
arguments: [ 'yufu_concept' ]
|
arguments: [ 'yufu_concept' ]
|
||||||
|
|
||||||
|
yufu_concept.translate:
|
||||||
|
class: Drupal\yufu_concept\Translate
|
||||||
|
arguments: ['@http_client', '@settings']
|
||||||
|
|
|
@ -181,8 +181,8 @@ $databases = [];
|
||||||
*
|
*
|
||||||
* WARNING: The above defaults are designed for database portability. Changing
|
* WARNING: The above defaults are designed for database portability. Changing
|
||||||
* them may cause unexpected behavior, including potential data loss. See
|
* them may cause unexpected behavior, including potential data loss. See
|
||||||
* https://www.drupal.org/developing/api/database/configuration for more
|
* https://www.drupal.org/docs/8/api/database-api/database-configuration for
|
||||||
* information on these defaults and the potential issues.
|
* more information on these defaults and the potential issues.
|
||||||
*
|
*
|
||||||
* More details can be found in the constructor methods for each driver:
|
* More details can be found in the constructor methods for each driver:
|
||||||
* - \Drupal\mysql\Driver\Database\mysql\Connection::__construct()
|
* - \Drupal\mysql\Driver\Database\mysql\Connection::__construct()
|
||||||
|
|
Loading…
Reference in New Issue