-
Notifications
You must be signed in to change notification settings - Fork 584
Conversation
PR for #111 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work on translating Alltube 😄
I added comments on a few things that might prevent gettext from working correctly.
templates/inc/head.tpl
Outdated
$language = "zh_CN"; | ||
putenv("LANG=".$language); | ||
setlocale(LC_ALL, $language); | ||
?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PHP code in template files won't be executed.
You need to put this in index.php for example.
@@ -0,0 +1,135 @@ | |||
msgid "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the gettext domain you are using is AllTube
this file should probably be named AllTube.po
.
composer.json
Outdated
@@ -13,7 +13,8 @@ | |||
"ptachoire/process-builder-chain": "~1.2.0", | |||
"guzzlehttp/guzzle": "~6.2.0", | |||
"rudloff/rtmpdump-bin": "~2.3", | |||
"aura/session": "~2.1.0" | |||
"aura/session": "~2.1.0", | |||
"smarty-gettext/smarty-gettext": "~1.2.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use smarty-gettext 1.5.1.
1.2.0 does not work correctly with the way Smarty is set up in Alltube.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a small change I had to make in order to make it work on my system.
Other than that, it works correctly. Thanks!
index.php
Outdated
|
||
$language = "zh_CN"; | ||
putenv("LANG=".$language); | ||
setlocale(LC_ALL, $language); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On some systems, the locale is called zh_CN.utf8
, so you should do something like this:
setlocale(LC_ALL, [$language, $language.'.utf8']);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not able to get the result even changing the setlocale to utf8, which I am really have no idea why. Do you have a sample site that you have done successfully? Also if you don't mind can you push the change to a different branch so I can look at it.
Codecov Report
@@ Coverage Diff @@
## master #112 +/- ##
=========================================
Coverage 99.72% 99.72%
Complexity 97 97
=========================================
Files 5 5
Lines 363 363
=========================================
Hits 362 362
Misses 1 1 Continue to review full report at Codecov.
|
OK, I see. But I cannot get it working. If possible it would be great that you put your changed code into a different branch (perhaps feature/translate) that I could take a look at. Along with that, can you make a option to choose different language? |
The only change I was talking about was the Note that you need to have the |
Yes, it would totally make sense to add this to |
That is exactly why I don't see it. I though it will render on the client instead on the server, but since it is a template it should be render on server.
What I mean is a switch on the web page, somewhere on the top right (or left), append url with locale=xx_XX (or cookie if you want to), instead of hardwired. At that case, I am not familiar with the implementation. |
I have merged your work into the feature/gettext branch. |
I am actually doing the options to switch language, and I am about half way there....although the method might get ugly. Yet I am not using cookie, so it will needed to switch every time. I will look into it and see how to do it. P.S. I just saw your work and I am going give up what I am going to do. But my thought so far: <?php
$trans_dir = '../i18n/Translations/*';
$globtrans = glob($trans_dir, GLOB_ONLYDIR);
foreach ($globtrans as $dlang)
{
$lang[] = $dlang;
//get array from glob, which find out what locale is available
}
foreach ($lang as $langpath) {
$langxpath[] = basename($langpath);
//get rid of path
}
foreach ($langxpath as $langlocale){
$displayname[] = locale_get_display_name($langlocale, $langlocale);
/**show the locale in its locale name, i.e.
français (France)
中文(中国)
中文(台灣)
**/
}
?> This is a good practice for me as I am learning php. 😆 |
Sorry, as you've seen, I started working on this myself. Also, I'm closing this pull request since I merged your code manually. |
Using the method provided by : https://github.com/smarty-gettext/smarty-gettext
Strings that are translated are not showing on the new page. Maybe somewhere I missed that should be included.