PiPass / blockpage

A temporary unblock solution and blockpage for your Pi-Hole system
BSD 3-Clause "New" or "Revised" License
196 stars 14 forks source link

Localization #7

Closed iroQuai closed 5 years ago

iroQuai commented 5 years ago

It would be great if there was an easy way to share localized versions of the block page. Is this easily doable?

roenw commented 5 years ago

Could you go into more detail? As in different languages?

iroQuai commented 5 years ago

I'm going to translate the block page into my native language, Dutch. It would be great if this option was facilitated some more. If, instead of editing the blockpage/index.php I could supply a separate translation file + an option to specify the displayed language (this last part could be part of the config.php)

Why is this useful? So the blockpage won't turn back to the standard English version after each update, sharing language files would be much easier and contributing by adding your own language for the community will be possible

JoeSchubert commented 5 years ago

This is actually a pretty good idea.

I think it would be possible to have a language translations xml or something, contain the strings in that for the page, then just read the strings from the appropriate section instead of hardcoding them into the php. The browser's preferred language should be readable in the page to decide which to serve.

iroQuai commented 5 years ago

I really like the way (amongst others) WordPress is using: https://developer.wordpress.org/themes/functionality/localization/

This way it'll be very easy for people to translate (parts of) language files, with online tools like https://poedit.net/

roenw commented 5 years ago

Great idea and good point! I almost forgot that everything would be reverted to English after an update. So, we would have some files, locale-en.php, locale-es.php, locale-de.php or whatever. The blockpage would look something like this:

require('/var/www/config.php')
if($conf['language']) {
   $langLocal = $conf['language'];
   require('/var/www/locale/locale-$langLocal);
} else {
   require('/var/www/locale/locale-en');
}

<alert>
<h1><i class="fa fa-shield"></i>  ?????</h1>
<p>?????</p>
</alert>

What would go in the question marks? I'd be fine with you guys creating a PR if you have time. I could work it into the admin panel once I know the syntax (or I could just steal it from your PR), you guys just know so much more about this than me.

Edit: Also, these locale files would be pushed to GitHub, so anyone can use them, correct?

JoeSchubert commented 5 years ago

I think that the easiest way to go about this would be to keep your formatting as in where the question marks and just use variables to contain the localized strings in the localization files. Then just call the variables with the text. You would of course need to default to something (English presumably) if the translation file doesn't exist.

And yes, presumably, people would create the translations that they wanted and push them to you.

The poedit thing is neat but looks specific to WordPress. Implementing that might be overly complicated for the small number of strings.

Also... This might be better to detect from the browser than making it a config item... https://stackoverflow.com/questions/3770513/detect-browser-language-in-php

roenw commented 5 years ago

I'll start working on it on branch beta-locales later. Poedit, like you said, would be nice but overkill for the small amount of text that's here.

iroQuai commented 5 years ago

I have little experience coding. I think I get how its done in php (same as how the beginning of the block page code says it requires ../config.php to check what the values of $conf['something'] is.)

So I guess what needs to be done (and I can do myself) is change every text-part with something like $text['name-of-textpart'] ?

If someone can give me a little affermation or explanation I will edit!

Something else though: something needs to be changed to effectively translate 'time-friendly' in config.php. in lots of translation files the terms 'minute' 'minutes' 'hour' and 'hours' are translated, and the code automatically changes the seconds in appropriate 'Xminutes and Yhours'.

roenw commented 5 years ago

@iroQuai, I have started implementation of localization already, and I’ll make some commits soon. It’s all sitting on my laptop right now. That is a great suggestion to eliminate time_friendly and have the code do that.

iroQuai commented 5 years ago

alright i'll just wait for those commits and start adding the dutch locales.

plankobostjan commented 5 years ago

@roenw any idea why I don't get locales-beta branch in my fork?

Anyway, I'll start working on Slovene locales.

roenw commented 5 years ago

@plankobostjan Sorry, I don’t have much experience in Git

plankobostjan commented 5 years ago

@roenw Okay, no problem. I've found a solution now.

If anybody else who has forked the @roenw's repo doesn't have a locales-beta branch in the fork (and wants to have it)... Here's what you need to do:

EDIT: Changed instructions so that you get the right version (latest commit) of @roenw's locales-beta branch.

Note: from here on I assume you work with git using command line on your local machine.

Add upstream (@roenw's) repository: git remote add upstream https://github.com/roenw/PiPass.git

Create empty branch locales-beta: git checkout --orphan locales-beta

Pull locales-beta from upstream: git pull upstream locales-beta

Push locales-beta to origin (your fork of PiPass repo): git push origin locales-beta

That's it. Now you have locales beta branch on you local machine and on your GitHub.

Hope this helps. :)