Skip to content

Commit

Permalink
Merge pull request #175 from humhub/enh/content-language
Browse files Browse the repository at this point in the history
Enh/content language
  • Loading branch information
luke- authored Aug 14, 2024
2 parents be52e1e + ae5fc1a commit 3b82466
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
4 changes: 4 additions & 0 deletions components/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use humhub\components\Controller;
use humhub\modules\content\models\Content;
use humhub\modules\rest\components\auth\ImpersonateAuth;
use humhub\modules\rest\components\behaviors\LanguagePickerBehavior;
use humhub\modules\rest\components\User as UserComponent;
use humhub\modules\rest\components\auth\JwtAuth;
use humhub\modules\rest\controllers\auth\AuthController;
Expand Down Expand Up @@ -81,6 +82,9 @@ public function behaviors()
]]
),
],
'languagePicker' => [
'class' => LanguagePickerBehavior::class,
]
], parent::behaviors());
}

Expand Down
28 changes: 28 additions & 0 deletions components/behaviors/LanguagePickerBehavior.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace humhub\modules\rest\components\behaviors;

use Yii;
use yii\base\Behavior;
use yii\helpers\ArrayHelper;
use yii\web\Controller;

class LanguagePickerBehavior extends Behavior
{
public function events()
{
return [
Controller::EVENT_BEFORE_ACTION => 'pickLanguage',
];
}

public function pickLanguage()
{
if (
empty(Yii::$app->request->acceptableLanguages) &&
$userLanguage = ArrayHelper::getValue(Yii::$app->user->identity, 'language')
) {
Yii::$app->language = $userLanguage;
}
}
}
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

0.10.2 (unreleased)
----------------------
- Enh #175: User language will be used by default

0.10.1 (July 31, 2024)
----------------------
- Enh #173: Added possibility to change `created_at` of `content`
Expand Down
4 changes: 4 additions & 0 deletions docs/MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Following RESTful API endpoints are available.

The base url for all APIs is: `https://yourhost/api/v1/`

**Language**

Logged-in user's language will be used. Can be overwritten by `Accept-Language` header.


**Core APIs:**

Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"keywords": [
"api", "rest"
],
"version": "0.10.1",
"version": "0.10.2",
"homepage": "https://github.com/humhub/rest",
"humhub": {
"minVersion": "1.16"
Expand Down

0 comments on commit 3b82466

Please sign in to comment.