petersphilo / humhub-social_stats

This is a HumHub module that provides general statistics on overall activity, with charts of hourly and daily activity
GNU General Public License v3.0
5 stars 2 forks source link

Add Translations #2

Closed ArchBlood closed 1 year ago

ArchBlood commented 1 year ago

Hello again, just stopping by to drop the first issue for you to tackle here on GitHub;

<?= Yii::t('SocialStatsModule.base', 'Your text here'); ?>

See the documentations for more information; https://docs.humhub.org/docs/admin/translations/#add-new-translations

petersphilo commented 1 year ago

oofa.. That'll take some time.. i'll get started on it soon..

petersphilo commented 1 year ago

i only know French, and a little Spanish.. Are there languages that should be given priority? DE?

marc-farre commented 1 year ago

If you want I can create the translations automatically with Google Translate API and push them to your module, but then it's better if you check that there a no big mistakes.

petersphilo commented 1 year ago

That's a kind offer! i will look into all of this next week, when my 2-do list doesn't have so many exclamation marks.. 🤪

marc-farre commented 1 year ago

I just had a look. Before I can do automatic translation, could you replace all your texts with <?= Yii::t('SocialStatsModule.base', 'The english text') ?>, the same way you did it for https://github.com/funkycram/humhub-social_stats/blob/main/Events.php#L41 ? Thanks.

petersphilo commented 1 year ago

Got it.. i'll look try to do that next week..

ArchBlood commented 1 year ago

Got it.. i'll look try to do that next week..

Sorry in advance, took a few minutes to work around all of the <span> 😅

Also fixed an issue where the PayPal button wouldn't display correctly 👍🏻

@funkycram this should help translations although as mentioned there are a lot of spans used so a lot of translation lines because of this.

marc-farre commented 1 year ago

@petersphilo I was waiting for @ArchBlood PR to be merged, but as it wasn't, I took the code he did in PR https://github.com/petersphilo/humhub-social_stats/pull/3, added auto translations, and created the PR https://github.com/petersphilo/humhub-social_stats/pull/7 So now, you can merge PR 7 and cancel PR 3. As translations are done automatically with Google Translate API, you should have a look to them.

ArchBlood commented 1 year ago

@petersphilo I was waiting for @ArchBlood PR to be merged, but as it wasn't, I took the code he did in PR https://github.com/petersphilo/humhub-social_stats/pull/3, added auto translations, and created the PR https://github.com/petersphilo/humhub-social_stats/pull/7 So now, you can merge PR 7 and cancel PR 3. As translations are done automatically with Google Translate API, you should have a look to them.

Could you link your PR to this issue in the description? fixes #2

marc-farre commented 1 year ago

@ArchBlood , when going to /social_stats/main/index, it seems there is a bug on https://github.com/ArchBlood/humhub-social_stats/blob/873f6beab2b7fe1f5b13b9dae379ed77b9f2c8f4/views/main/index.php#L233 Thanks.

ArchBlood commented 1 year ago

@ArchBlood , when going to /social_stats/main/index, it seems there is a bug on https://github.com/ArchBlood/humhub-social_stats/blob/873f6beab2b7fe1f5b13b9dae379ed77b9f2c8f4/views/main/index.php#L233 Thanks.

I'll take a look over it, although I'm not seeing any errors on my end

marc-farre commented 1 year ago

Thanks. This is the error log on Humhub 1.12.1 with https://raw.githubusercontent.com/ArchBlood/humhub-social_stats/873f6beab2b7fe1f5b13b9dae379ed77b9f2c8f4/views/main/index.php

yii\base\ErrorException: Array to string conversion in /var/www/hhdev/protected/modules/social_stats/views/main/index.php:233 Stack trace:

0 /var/www/hhdev/protected/modules/social_stats/views/main/index.php(233): yii\web\ErrorHandler->handleError(code: '...', message: '...', file: '...', line: '...')

1 /var/www/hhdev/protected/vendor/yiisoft/yii2/base/View.php(347): humhub\modules\ui\view\components\View->unknown()

2 /var/www/hhdev/protected/vendor/yiisoft/yii2/base/View.php(257): humhub\modules\ui\view\components\View->renderPhpFile(file: '...', params: '...')

3 /var/www/hhdev/protected/vendor/yiisoft/yii2/base/View.php(156): humhub\modules\ui\view\components\View->renderFile(viewFile: '...', params: '...', context: '...')

4 /var/www/hhdev/protected/vendor/yiisoft/yii2/base/Controller.php(407): humhub\modules\ui\view\components\View->render(view: '...', params: '...', context: '...')

5 /var/www/hhdev/protected/modules/social_stats/controllers/MainController.php(44): humhub\modules\social_stats\controllers\MainController->render(view: '...', params: '...')

6 /var/www/hhdev/protected/vendor/yiisoft/yii2/base/InlineAction.php(57): humhub\modules\social_stats\controllers\MainController->actionIndex()

7 /var/www/hhdev/protected/vendor/yiisoft/yii2/base/InlineAction.php(57): ::call_user_func_array:{/var/www/hhdev/protected/vendor/yiisoft/yii2/base/InlineAction.php:57}(callback: '...', args: '...')

8 /var/www/hhdev/protected/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(params: '...')

9 /var/www/hhdev/protected/vendor/yiisoft/yii2/base/Module.php(552): humhub\modules\social_stats\controllers\MainController->runAction(id: '...', params: '...')

10 /var/www/hhdev/protected/vendor/yiisoft/yii2/web/Application.php(103): humhub\components\Application->runAction(route: '...', params: '...')

11 /var/www/hhdev/protected/vendor/yiisoft/yii2/base/Application.php(384): humhub\components\Application->handleRequest(request: '...')

12 /var/www/hhdev/index.php(25): humhub\components\Application->run()

13 {main}

ArchBlood commented 1 year ago

Thanks. This is the error log on Humhub 1.12.1 with https://raw.githubusercontent.com/ArchBlood/humhub-social_stats/873f6beab2b7fe1f5b13b9dae379ed77b9f2c8f4/views/main/index.php

yii\base\ErrorException: Array to string conversion in /var/www/hhdev/protected/modules/social_stats/views/main/index.php:233 Stack trace: #0 /var/www/hhdev/protected/modules/social_stats/views/main/index.php(233): yii\web\ErrorHandler->handleError(code: '...', message: '...', file: '...', line: '...') #1 /var/www/hhdev/protected/vendor/yiisoft/yii2/base/View.php(347): humhub\modules\ui\view\components\View->unknown() #2 /var/www/hhdev/protected/vendor/yiisoft/yii2/base/View.php(257): humhub\modules\ui\view\components\View->renderPhpFile(file: '...', params: '...') #3 /var/www/hhdev/protected/vendor/yiisoft/yii2/base/View.php(156): humhub\modules\ui\view\components\View->renderFile(viewFile: '...', params: '...', context: '...') #4 /var/www/hhdev/protected/vendor/yiisoft/yii2/base/Controller.php(407): humhub\modules\ui\view\components\View->render(view: '...', params: '...', context: '...') #5 /var/www/hhdev/protected/modules/social_stats/controllers/MainController.php(44): humhub\modules\social_stats\controllers\MainController->render(view: '...', params: '...') #6 /var/www/hhdev/protected/vendor/yiisoft/yii2/base/InlineAction.php(57): humhub\modules\social_stats\controllers\MainController->actionIndex() #7 /var/www/hhdev/protected/vendor/yiisoft/yii2/base/InlineAction.php(57): ::call_user_func_array:{/var/www/hhdev/protected/vendor/yiisoft/yii2/base/InlineAction.php:57}(callback: '...', args: '...') #8 /var/www/hhdev/protected/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(params: '...') #9 /var/www/hhdev/protected/vendor/yiisoft/yii2/base/Module.php(552): humhub\modules\social_stats\controllers\MainController->runAction(id: '...', params: '...') #10 /var/www/hhdev/protected/vendor/yiisoft/yii2/web/Application.php(103): humhub\components\Application->runAction(route: '...', params: '...') #11 /var/www/hhdev/protected/vendor/yiisoft/yii2/base/Application.php(384): humhub\components\Application->handleRequest(request: '...') #12 /var/www/hhdev/index.php(25): humhub\components\Application->run() #13 {main}

Seems to be with the original code, nothing that I personally did 🤔

Here's an example of how it should be setup where you see '' this should print the array or string variable requested.

<?php $MyAssets = humhub\modules\social_stats\Assets::register($this); ?>
<script <?= Html::nonce() ?> type='module' src='<?= $MyAssets->baseUrl . '/' . $MyAssets->js[0] = ''; ?>'></script>
<script <?= Html::nonce() ?> type='module' src='<?= $MyAssets->baseUrl . '/' . $MyAssets->js[1] = ''; ?>'></script>
<script <?= Html::nonce() ?> ='module' src='<?= $MyAssets->baseUrl . '/' . $MyAssets->js[2] = ''; ?>'></script>
<script <?= Html::nonce() ?> type='module' src='<?= $MyAssets->baseUrl . '/' . $MyAssets->js[3] = ''; ?>'></script>
<script <?= Html::nonce() ?> type='module' src='<?= $MyAssets->baseUrl . '/' . $MyAssets->js[4] = ''; ?>'></script>
<script <?= Html::nonce() ?> src='<?= $MyAssets->baseUrl . '/' . $MyAssets->js[5] = ''; ?>'></script>

Of course you should also think of using camelCase instead of using PascalCase @petersphilo, as it is slightly more preferred when using a variable.

ArchBlood commented 1 year ago

Of course you can also use something like the following which should also work as well; https://stackoverflow.com/questions/48685676/php-notice-yii-base-errorexception-with-message-array-to-string-conversion

petersphilo commented 1 year ago

Done! Finally! French, Spanish, and German translations added.. Although, they are straight-up Google Translate translations, so they're probably terrible..