userfrosting / UserFrosting

Modern PHP user login and management framework
https://www.userfrosting.com
Other
1.63k stars 366 forks source link

Translating UF interface #145

Closed Ctbmaz closed 9 years ago

Ctbmaz commented 9 years ago

I'm testing Userfrosting right now and I noticed there is an option to select language. But it looks like it don't work. I tried to switch to es file included in translation directory but nothing changed. There was some Spanish mesage sometimes but overall the UF pages remained in english. Is there a way to translate UF to other language? I would like to translate it to Polish.( I tried to create new file called pl based on English file and translated all message strings in it to polish but as I said it did nothing. Do I have to translate something else too? I'm interested into translating all aspects of interface not just messages. Is there a way to do that ?

lilfade commented 9 years ago

Most of the text you see in the interface is hard coded or stored into the database. We currently looking at how to decouple the interface from the code in the best way to also allow major changes without having to break the interface. If you come up with a way to do this you can create a pull request we can review to change.

alexweissman commented 9 years ago

I think this is, again, something we could solve with a unified templating system. All the text, and not just error messages, could be linked up through hooks.

lilfade commented 9 years ago

Ill take a look at the templating system next, it seems to be the next big thing we need to look at.

lilfade commented 9 years ago

Im gonna make a change to how the nav system works i believe, @Ctbmaz would you be willing to write the polish for the lang file as well as translate these for me:

Admin Dashboard
Users
Dashboard
Account Settings
Site Settings
Site Configuration
Groups
Authorization
Account Settings
Log Out

if you can do this then i can make a test for you to try which would change some more things on the general website.

lilfade commented 9 years ago

Will probably need more translation done as well after this if you don't mind to fix some other language areas as well once i get some more hooks setup.

lilfade commented 9 years ago

Also #114 @arochwer if you could do the same if your around still.

Ctbmaz commented 9 years ago

I think the polish translation to these should be this. Few of these could be handled in few ways in polish so it is possible that someone may have another translation. Admin Dashboard - 'Konsola Administratora' Users -'Użytkownicy' Dashboard -'Konsola' Account Settings -'Ustawienia Konta' Site Settings- 'Ustawiena Strony' Site Configuration 'Konfiguracja Strony' Groups 'Grupy' btw Users Groups -'Grupy Użytkowników' Authorization Autoryzacja Account Settings -'Ustawienia Konta' Log Out -'Wylogowanie'

lilfade commented 9 years ago

Ok thanks a bunch I got a idea to handle some text for languages still thinking about templating on the other hand. I'll link a test for you later on once I get this nailed down. On Nov 5, 2014 9:02 AM, "Ctbmaz" notifications@github.com wrote:

I think the polish translation to these should be this. Few of these could be handled in few ways in polish so it is possible that someone may have another translation. Admin Dashboard - 'Konsola Administratora' Users -'U¿ytkownicy' Dashboard -'Konsola' Account Settings -'Ustawienia Konta' Site Settings- 'Ustawiena Strony' Site Configuration 'Konfiguracja Strony' Groups 'Grupy' btw Users Groups -'Grupy U¿ytkowników' Authorization Autoryzacja Account Settings -'Ustawienia Konta' Log Out -'Wylogowanie'

Reply to this email directly or view it on GitHub https://github.com/alexweissman/UserFrosting/issues/145#issuecomment-61819802 .

alexweissman commented 9 years ago

@lilfade, we might want to consider using PHP's standard internationalization library for this, gettext. I'm not sure how commonly available it is, but it does seem to be installed by default on my web server at least.

Basically, there is a concept known as i18n, which has some standard practices for how to implement language support properly. Because, apparently a lot of people do it improperly.

Honestly though, for databases it doesn't seem like any of the existing solutions are all that elegant. Most of what I'm seeing involves keeping a separate table for translations. e.g., https://stackoverflow.com/questions/929410/what-are-best-practices-for-multi-language-database-design

But, not all of our content is stored in the database. So, we need something that unifies language support across dynamic (database-driven) content, and content found in the templates. Maybe this is our chance to come up with something really groundbreaking ;)

lilfade commented 9 years ago

Yea i was looking into i18n last night didn't get too far but i was thinking a simple class could take care of translation from a language file (we should support real language names for file names though eg. en -> en_US, es -> es_ES, pl -> pl_PL ect.

I was asking for those translations to use for the nav menus which will cover the main areas most users will see that they will use more often. I can assume a polish website the chuck of the content will be in polish rather then english so we just have to take content out of the backend yet and have it replaced on the fly when a different language is chosen.

I should have some time tonight to make a couple changes, we'll see what happens ^_^

Edit: Server is down waiting to hear back from my hosting company ... ill go from when that comes up i found some useful information from searching tonight for i18n. Ill try to apply some changes and do a pull when i can will probably move a bunch of stuff around so it may take a day or two.

alexweissman commented 9 years ago

Cool. I really like the way we use hooks in the nav_menu table. I could see language selection as working on the same principle, with unique hooks in the table instead of the actual values.

This could be encapsulated inside the ORM, so when you call one of the CRUD functions, you can also optionally specify a language. For example:

fetchMenu($user_id, $language = 'en_US')

The ORM could be responsible not only for loading the DB data, but also making the appropriate translations to the requested language.

We wouldn't even necessarily need to specify a language for every call to the ORM, this could be done in some sort of initialization call.

lilfade commented 9 years ago

I think thats a great idea, we should get that orm idea made into a script #88

I think using language abstraction like this would be awesome, using the hooks to replace with what we need would be nice. What would we do just have a tag in the db and reference that tag/hook in the lang files to pull what language text we need?

alexweissman commented 9 years ago

Yeah, that's the idea. I just asked on the RedBean page (https://github.com/gabordemooij/redbean/issues/397) to see if they'd consider supporting this feature.

Parmenio commented 9 years ago

I need to translate the system to Spanish. if you wish, I can do the translation.

alexweissman commented 9 years ago

That would be awesome. We already have a partial translation in models/languages/es.php. But, we still need a translation for the (currently) hard-coded messages.

Parmenio commented 9 years ago

I need the system in Spanish. I'm about to begin translating the hard-coded messages, but if you give me a list of the message, I can translate them before.

alexweissman commented 9 years ago

Can you keep a text file/spreadsheet with the messages, and their corresponding translations? We can incorporate them into the next version, which I hope will have a more comprehensive internationalization system.

alexweissman commented 9 years ago

Here is a sneak preview of how I am hoping to implement this in the future for error messages:

{
    "user_name" : {
        "validators" : {
            "length" : {
                "min" : 1,
                "max" : 50,
                "messages" : {
                    "default" : "'Username' must be between 1 and 50 characters long.",
                    "es_US" : "Su nombre de usuario debe estar entre 1 y 50 caracteres de longitud"
                }
            }
        }
    },
    "display_name" : {
        "validators" : {
            "length" : {
                "min" : 1,
                "max" : 50,
                "messages" : {
                    "default" : "'Display name' must be between 1 and 50 characters long.",
                    "es_US" : "Su nombre debe estar entre 1 y 50 caracteres de longitud"
                }
            },
            "required" : {
                "messages" : {
                    "default" : "'Display name' is required.",
                    "es_US" : "Por favor, ingrese su nombre"
                }
            }
        }
    },          
    "email" : {
        "validators" : {
            "length" : {
                "min" : 1,
                "max" : 150,
                "messages" : {
                    "default" : "'Email' must be between 1 and 150 characters long.",
                    "es_US" : "Dirección de correo electrónico debe estar entre 1 y 150 caracteres de longitud"
                }
            },
            "email" : {
                "messages" : {
                    "default" : "'Email' must be a valid email address.",
                    "es_US" : "Dirección de correo electrónico no válida"
                }
            }
        }
    },
    "title" : {
        "validators" : {
            "length" : {
                "min" : 1,
                "max" : 150,
                "messages" : {
                    "default" : "'Title' must be between 1 and 150 characters long.",
                    "es_US" : "Los títulos deben estar entre 1 y 150 caracteres de longitud"
                }
            }
        }
    },
    "password" : {
        "validators" : {
            "length" : {
                "min" : 8,
                "max" : 50,
                "messages" : {
                    "default" : "'Password' must be between 8 and 50 characters long.",
                    "es_US" : "La contraseña debe tener entre 8 y 50 caracteres de longitud"
                }
            }
        }      
    },
    "beard" : {
        "validators" : {
            "required" : {
                "messages" : {
                    "default" : "'You must select a beard."
                }
            }
        }      
    }
}
c3-h8 commented 9 years ago

Nice idea. I would contriubute german.

arochwer commented 9 years ago

@lilfade hey! sorry i just got around this... what you need my help with?

alexweissman commented 9 years ago

I have implemented a custom function in Twig, translate, which looks up a message token and translates into the user's currently selected language. For example, https://github.com/alexweissman/UserFrosting/blob/dev-0.3.0/userfrosting/templates/themes/default/menus/sidebar.html#L25:

<a href="{{site.uri.public}}/users"><i class="fa fa-users fa-fw"></i> {{ translate("MENU_USERS") }}</a>

This looks for the MENU_USERS token in the corresponding language file. Many of the language files are out-of-date (with en_US being the canonical up-to-date file). Some help updating these translations, and providing new languages, would be great.

alexweissman commented 9 years ago

See #360.