[wp-hackers] What do you name the localization .mo when the locale is not set?

Wordpress Developer wordpress.development at gmail.com
Thu Jun 17 15:36:00 UTC 2010


There must have been some higher-level code in the theme -- huge, not coded
by me -- that was unsetting the locale. Setting it in wp-config.php didn't
change the output of my unit test and I couldn't reset it on the fly.

But I went into the code for load_theme_textdomain() and saw it was more or
less just a stub for load_textdomain(). Just called that instead, specifying
the .mo filepath myself, and voila -- it works.

If you can specify the $path, I wonder why you can't just specify the
location of the .mo? Maybe the design was intended to enforce "good coding
practices" or whatever and make people name their .mo a certain way. In any
case, a more direct approach worked better for me.

Thanks Frank and Otto for your responses. I plan to hang around this mailing
list more often and answer some questions when I have answers, so perhaps I
can soon return the favor.

function load_child_theme_textdomain
<../_functions/load_child_theme_textdomain.html>($domain
<../_variables/domain.html>, $path <../_variables/path.html> = false)
{ 419          $locale <../_variables/locale.html> = get_locale
<../_functions/get_locale.html>(); 420   421          $path
<../_variables/path.html> = ( empty( $path <../_variables/path.html> )
) ? get_stylesheet_directory
<../_functions/get_stylesheet_directory.html>() : $path
<../_variables/path.html>; 422   423          $mofile
<../_variables/mofile.html> = "$path <../_variables/path.html>/$locale
<../_variables/locale.html>.mo"; 424          return load_textdomain
<../_functions/load_textdomain.html>($domain
<../_variables/domain.html>, $mofile <../_variables/mofile.html>); 425
 }


On Thu, Jun 17, 2010 at 8:13 AM, Otto <otto at ottodestruct.com> wrote:

> The default is indeed en_US. See the get_locale() function in the l10n.php
> file.
>
> -Otto
>
>
>
> On Thu, Jun 17, 2010 at 10:02 AM, Wordpress Developer
> <wordpress.development at gmail.com> wrote:
> > I'm working on a localized template and have my .mo working fine for
> default
> > installs of WP. Love it: Just use _e('whatever', 'textdomain') and it
> echos
> > out the value based on the "whatever" key.
> >
> > Unfortunately, my code fails after taking it from my personal dev
> > environment into a professional one. I've troubleshooted what I can and
> > think it's because the locale is not set on the new dev environment. I
> ran
> > this code to check:
> >
> > <?php
> > $locale = get_locale();
> > if($locale == "en_US") {
> >   echo "english: $locale";
> > } else { echo "not english: $locale"; } ?>
> >
> > In the working dev environment, it echos out "english: en_US"
> >
> > In the non-working dev environment, it echos out "not english: "
> >
> > In both installs the WP_Lang constant is not set (wp-config: "define
> > ('WPLANG', '');"). It's a bit confusing to me as to why one install
> defaults
> > to en_US (as I might expect) but the other doesn't seem to have the
> locale
> > set at all. In any case, I suspect my .mo is failing because it's named
> > en_US.mo in the theme folder and since the locale on the second setup is
> not
> > en_US it's not finding it.
> >
> > In any case, I figure my .mo has a chance if I name it the right thing
> for a
> > WP install with no language set. Is there such a namespace? What do you
> name
> > the localization .mo when the locale doesn't seem to be set?
> >
> > Thank you!
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list