From: Daniel Karbach Date: Tue, 23 Aug 2022 08:45:48 +0000 (+0200) Subject: technique translations X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=6f34dd7c00bf0bd152a97b175390be00c3a0ba31;p=alttp.git technique translations --- diff --git a/app/Models/Technique.php b/app/Models/Technique.php index 1a54a0e..256afc0 100644 --- a/app/Models/Technique.php +++ b/app/Models/Technique.php @@ -17,7 +17,16 @@ class Technique extends Model ->using(TechniqueChapter::class); } + public function translations() { + return $this->hasMany(TechniqueTranslation::class); + } + protected $casts = [ 'index' => 'boolean', ]; + + protected $with = [ + 'translations', + ]; + } diff --git a/app/Models/TechniqueTranslation.php b/app/Models/TechniqueTranslation.php new file mode 100644 index 0000000..e7c7603 --- /dev/null +++ b/app/Models/TechniqueTranslation.php @@ -0,0 +1,11 @@ +id(); + $table->foreignId('technique_id')->constrained(); + $table->string('locale'); + $table->text('title'); + $table->text('short'); + $table->text('description'); + $table->timestamps(); + $table->unique(['technique_id', 'locale']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('technique_translations'); + } +}; diff --git a/resources/js/components/techniques/Detail.js b/resources/js/components/techniques/Detail.js index d586a9a..d955397 100644 --- a/resources/js/components/techniques/Detail.js +++ b/resources/js/components/techniques/Detail.js @@ -1,19 +1,30 @@ import PropTypes from 'prop-types'; import React from 'react'; import { Container } from 'react-bootstrap'; +import { withTranslation } from 'react-i18next'; import Outline from './Outline'; +import { getTranslation } from '../../helpers/Technique'; +import i18n from '../../i18n'; const Detail = ({ technique }) => -

{technique.title}

+

{getTranslation(technique, 'title', i18n.language)}

-
+
{technique.chapters ? technique.chapters.map(chapter =>
{chapter.pivot.level ? - React.createElement(`h${chapter.pivot.level}`, {}, chapter.title) + React.createElement( + `h${chapter.pivot.level}`, + {}, + getTranslation(chapter, 'title', i18n.language), + ) : null} -
+
) : null} ; @@ -27,4 +38,4 @@ Detail.propTypes = { }), }; -export default Detail; +export default withTranslation()(Detail); diff --git a/resources/js/components/techniques/Outline.js b/resources/js/components/techniques/Outline.js index bf98eba..ae18aa8 100644 --- a/resources/js/components/techniques/Outline.js +++ b/resources/js/components/techniques/Outline.js @@ -1,6 +1,10 @@ import PropTypes from 'prop-types'; import React from 'react'; import { ListGroup } from 'react-bootstrap'; +import { withTranslation } from 'react-i18next'; + +import { getTranslation } from '../../helpers/Technique'; +import i18n from '../../i18n'; const Outline = ({ technique }) => technique.chapters && technique.chapters.length ?