Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.2][new feature] little native language system (internationalization, i18n) #582

Closed
Dominic28 opened this issue Jan 30, 2015 · 9 comments

Comments

@Dominic28
Copy link
Contributor

Hey,
As you made it possible to load text with Text::get(), I created a very simple language system with it. I let the user choose the language while registering and save it to the database. Then I'm just checking which file needs to be loaded in the text class.

Additionally I'm reading out $_SERVER['HTTP_ACCEPT_LANGUAGE'] to show unregistered users the site in their prioritized language (if available).

Are you interested in this simple solution? Because you said it's not really needed some time ago.
I can't create a pull-request now as my version of huge is too different, that's why I'm asking.

@panique
Copy link
Owner

panique commented Jan 30, 2015

Hi Dominic, in generell it's a good feature, but I think it might be better to keep the focus on the login system and don't integrate any features that are related to the login process!

In the old php-login process there was a internationalization feature but this made things much more complicated.

Maybe, if it's extremely easy and a fully independet class: Can you show a little bit of code ?

Thanks & have a nice day

@Dominic28
Copy link
Contributor Author

Basically it's just this part. You can see I moved the text-file from the config folder to a language folder and created folders for each language (like app/lang/en).

unbenannt

@panique
Copy link
Owner

panique commented Jan 30, 2015

I love the simplicity of your code! Good stuff, this should definitly go into the project! Let's discuss this a little bit, maybe there are pros / cons and other have different opinions.

My suggestions:

  1. maybe move the internationalization-part to an own method, so it can be used / not used with one line of code. Also good for potential upcoming unit tests.
  2. the definition of the language (= WHERE and HOW will be defined which language the user sees) should be discussed

Good feature! Thanks for coming up with this proposal!

@panique panique changed the title [No Issue] Little language system [3.1][new feature] little native language system (internationalization, i18n) Jan 30, 2015
@Dominic28
Copy link
Contributor Author

Thanks! I even removed the switch, so the language-file is searched just by the content of the user_lang session (with strip_tags).

To detect the language I got this in the constructor of app/core/controller.php

if (empty(Session::get("user_lang"))) {
    if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
        // Save the first two letters to the session
        Session::set("user_lang", strtolower(trim(strip_tags(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2)))));
    }
}

Parts of this are from stackoverflow. But I would need to search for a link.

@Dominic28
Copy link
Contributor Author

I found a smaller problem with my solution. If you got multiple language files, you always need to get sure that each language file contains every text. Otherwise there will be an empty place on the site.

Example:
You got the following entry in the english language array: "MENU_LINK_HOME" => "Home" but you forgot to set it up in the other languages.

This could be solved by requirering the language array, check the array for the entry and load the standard language if it's empty.

@panique panique changed the title [3.1][new feature] little native language system (internationalization, i18n) [3.2][new feature] little native language system (internationalization, i18n) Mar 9, 2015
@panique panique added the v3.x label Mar 14, 2015
@panique
Copy link
Owner

panique commented Oct 11, 2015

Hey, I've linked this feature from the project's readme in case somebody wants to implement this.

Hope if it's okay for you when i close this ticket.

@panique panique closed this as completed Oct 11, 2015
@ghost
Copy link

ghost commented Mar 3, 2016

I know this is old. I've made something like this and copy now some of your code.

About missing text:
"This could be solved by requirering the language array, check the array for the entry and load the standard language if it's empty."

I've something different for this:

if (file_exists('../application/lang/'.$lang.'/strings.php')) {
    self::$texts = require('../application/lang/'.$lang.'/strings.php');
} else {
    self::$texts = require('../application/lang/de/strings.php');
}

Become ->

self::$texts = require('../application/lang/de/strings.php');
if (file_exists('../application/lang/'.$lang.'/strings.php')) {
    self::$texts = require('../application/lang/'.$lang.'/strings.php');
}

So, you load main language and override only exist strings. But really don't know which is better, double request or a check for each string call?

Thanks for your code!

@Kayumba
Copy link

Kayumba commented Nov 13, 2017

Hello, I use huge login for my application. I would like to use several languages(tongues) in the application. Somebody has a directory containing everything.
I also ask you for the translation of this in French

Return array ("FEEDBACK_UNKNOWN_ERROR" = > " Unknown error occurred! ", "FEEDBACK_DELETED" = > " Your account has been deleted. ", "FEEDBACK_ACCOUNT_SUSPENDED" = > " Account Suspended for ",
thank you

@mauro-balades
Copy link

self::$texts = require('../application/lang/de/strings.php');
if (file_exists('../application/lang/'.$lang.'/strings.php')) {
self::$texts = require('../application/lang/'.$lang.'/strings.php');
}

Remember to check if texts exist!

if (!self::$texts)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants