denise: Image: Me, facing away from camera, on top of the Castel Sant'Angelo in Rome (Default)
Denise ([staff profile] denise) wrote in [site community profile] dw_dev_training2011-08-19 12:07 pm

*bangs head against translation system*

Scenario: I have a dw-nonfree file (cgi-bin/DW/Hooks/Community.pm) in which I want to reference text that is a mixture of both en_DW.dat (dw-nonfree version) and FAQs from en.dat (dw-free version). (Namely: I am referencing FAQs in the code, and would like the FAQ titles to automatically update in the page if they update on the site.)

I thought this would work:



However, although I do have a FAQ #17 on my 'hack, it comes up as:

[missing string 17.1question]

I'm suspecting it's because I need to declare the 'faq' scope instead of the 'general' scope, but can I intermingle things from faq and general? Is there an easier way to be doing what I want to do?
sophie: A cartoon-like representation of a girl standing on a hill, with brown hair, blue eyes, a flowery top, and blue skirt. ☀ (Default)

[personal profile] sophie 2011-08-19 05:03 pm (UTC)(link)
The FAQ pages seem do to do it by loading the LJ::Faq object and then getting it from there. Something like this might work (although I don't think this will respect the user's language settings - not that we have any different languages on this site, but other sites might):

my $faq = LJ::Faq->load( 17 );
$ret .= "<li><a href='blah'>" . $faq->question_html . "</a></li>";


If you want languages respected, then this is probably the right way to do it (with the first half of this pretty much directly copied from htdocs/support/faqbrowse.bml; the only thing I edited was taking away the detection of the ?lang= URL parameter):

# get language settings
my $curlang = BML::get_language();
my $deflang = BML::get_language_default();
my $altlang = $curlang ne $deflang;
my $mll = LJ::Lang::get_lang($curlang);
my $mld = LJ::Lang::get_dom("faq");
$altlang = 0 unless $mll && $mld;
my $lang = $altlang ? $curlang : $deflang;

my $faq = LJ::Faq->load( 17, lang => $lang );
$ret .= "<li><a href='blah'>" . $faq->question_html . "</a></li>";


Oh, you may want to make sure $faq actually exists too, thinking about it; if the FAQ isn't there then that code would fail when it tries to access 'question_html'.
Edited (Escaping HTML is a good thing. So are languages. And getting arguments right.) 2011-08-19 17:11 (UTC)