Jump to content

Language code field for language template


Jacked
 Share

Recommended Posts

Just a thought:

Since it sucks so badly to always have to check for this 'default' language and, why not

add a new field to language template called 'code'

This way there will still be a 'default' laguage for the system, but also an easy and COHERENT way to check languages - probably $user->language->code will work just out of the box?

And one more thing - I would really need the solution 'right away', so if somebody could write some browser-code i could work on, or show me how to make 'languages' template visible in template list, it would be really appreciated ;-)

Link to comment
Share on other sites

Why do you have to check this always?

As for your second idea:

Got to: Setup -> Templates -> Filters -> Show System Templates? -> Yes

Edit the "language" template, add a textfield "code" and set your language code ;)

  • Like 2
Link to comment
Share on other sites

Hi Jacked and welcome to forums.

Not sure what is the problem you are trying to solve. But yes, it is minor annoyance that you have to always choose the language when creating users (the default lang should be ticked by default, I think).

Link to comment
Share on other sites

riiight, didn't expect to find it in 'filters'...

I love the clean admin area of processwire, but there are some ui issues...

...well, let's just say that it's sometimes obvious that the cms was created by a programmer ;-)

and i'm doing a multilanguage site with localised urls that works in a different way than 'language gateway', and thought that such a field mught come in handy

am having a hard time though, since i'm more of a designer than coder, haha

Link to comment
Share on other sites

I still don't get what the problem is. "language" template you don't need to do anything anyway, that's why it's a system template.

Getting language is simply $user->language->name. And you'd have to do this once in your templates code if you do it "right". 

riiight, didn't expect to find it in 'filters'...

I love the clean admin area of processwire, but there are some ui issues...

...well, let's just say that it's sometimes obvious that the cms was created by a programmer ;-)

Actually Ryan is a designer and coder, and compared to most out there, that call themselfs designers, he's even better. ;-) I don't think there's much UI issues, well not more than with any other CMS software.

and i'm doing a multilanguage site with localised urls that works in a different way than 'language gateway', and thought that such a field mught come in handy

Localized urls? You mean using the LanguageLocalizedURL module? Even there you don't really need a extra field.

am having a hard time though, since i'm more of a designer than coder, haha

Yeah it's obvious. :D

Link to comment
Share on other sites

Jacked,

For multilang Websites which need localized urls, there's a great module: http://modules.processwire.com/modules/language-localized-url/

If you have problems or questions, it's always best to give some details what you want to achive and also share some code-snippets. The people

here are very helpful.

Btw, ryan is also a designer and I think that Processwire's backend is the best so far in terms of usability. Just take some time to explore Processwire and how it works, you can do everything with it ;-)

Link to comment
Share on other sites

yeah, i don't really like the whole 'language gateway' concept, because I believe that a 'default' language should not need any additional segments - as in default

also - it needs adding additional pages when more languages are added and, not that i need it right now ( :> ) but i like permanent solutions

that's also why i need the language code - this way i don't have to hardcode anything (like if default then 'en', else 'de')

and, back to ui - don't get me wrong: i checked MOST of the cms's and processwire was THE BEST out there when it comes to admin UI, custom fields handling and multi-language support - though i do miss multilanguage for fields other than text (i.e. - images) - now they have to be hardcoded (have seperate fields done), and that requires maintance if new languages are to be added (because it's easy to teach someone how to add a new language, and hard to teach him how to add new fields and assign them to templates ;-)

Link to comment
Share on other sites

The best way to check if the language is default is:

$user->language->isDefault(); 

…but if you prefer to add your own fields to the Language template (like 'code') then that's fine too. Another alternative is that you could add your own defines to a common include, and then compare against them. 

define("EN", 123); // ID of english language page
define("ES", 456); // ID of Spanish language page
define("FR", 789); // ID of French language page

Then whenever you want to compare a user's language, you could do something like this: 

if($user->language == FR) {
  // user's language is french
}
 though i do miss multilanguage for fields other than text (i.e. - images) -

We will be adding more multi-language fieldtypes as time goes on. Thus far there hasn't been a lot of demand for more than the ones we've already got, but it's always been the plan to keep adding more. 

  • Like 2
Link to comment
Share on other sites

The thing with multilanguage fields for images is that i.e. if you have a news site with sliders, you're probably going to write headlines on the images themselves - and if you have news in different languages... then you have to do alternate fields etc.

anyways: additional field for language code works like a charm for me, as it differentiates code from content: nowhere in my code do i have to hardcode what my default language is, neither do i have to account for all languages i already have (or might have in the future)

Thanks a lot for taking time to answer - I must say that the support here from both ryan himself and other moderators is just perfect. Really making things easier.

  • Like 1
Link to comment
Share on other sites

nowhere in my code do i have to hardcode what my default language is, neither do i have to account for all languages i already have (or might have in the future)

This is actually the purpose of $user->language->isDefault(), so that you can differentiate the default site language from all others in one shot, without having a dependency on any specific language. This is largely contextual to a website. If a new user arrives at your website and has not selected a language, what do they get? That's what the default language is about.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...