Foros de discusión

How to get articles by locale

علي خسروي, modificado hace 16 años.

How to get articles by locale

New Member Mensajes: 3 Fecha de incorporación: 14/01/08 Mensajes recientes
hi

i am using xsl template to retrieve last news articles and using this xsl template

<!--?xml version="1.0"?-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" omit-xml-declaration="yes" />
<xsl:template match="/">
<div class="journal-rss-feed-reader-container">

<xsl:variable name="articles" select="document('http://@portal_url@/c/journal/get_articles?groupId=@group_id@&amp;templateId=BASIC-RSS-ITEM&amp;delta=100&amp;orderBy=display-date')/result-set/result" />

<xsl:for-each select="$articles">
<div class="journal-rss-feed-item-container">

<h2>
<a>
<xsl:attribute name="href">
<xsl:value-of disable-output-escaping="yes" select="root/dynamic-element[@name='link']/dynamic-content" />
</xsl:attribute>
<xsl:if test="root/dynamic-element[@name='new-window']/dynamic-content = 'true'">
<xsl:attribute name="target">
<xsl:text>_blank</xsl:text>
</xsl:attribute>
</xsl:if>
<xsl:value-of disable-output-escaping="yes" select="reserved-info/title" />
<xsl:value-of disable-output-escaping="yes" select="root/dynamic-element[@name='headline']/dynamic-content" />
</a>
</h2>

<p class="date-creator">
<script language="JavaScript1.2">
str="<xsl:value-of disable-output-escaping="yes" select="root/dynamic-element[@name='reserved-article-display-date']/dynamic-content"/>";
ar=str.split(" ");
document.write(ar[0]+" "+ar[2]+" "+ar[1]+" "+ar[3]);
</script>
<xsl:text> (</xsl:text>
<xsl:value-of disable-output-escaping="yes" select="root/dynamic-element[@name='creator']/dynamic-content" />
<xsl:text>)</xsl:text>
</p>

<p>
<xsl:value-of disable-output-escaping="yes" select="root/dynamic-element[@name='description']/dynamic-content" />
</p>
</div>
<br>
</xsl:for-each>

</div>
</xsl:template>
</xsl:stylesheet>


but this code always return en_US articles and i want this code return fa_IR article.

i see in get_articles action use theme locale for retrieving content but in my portal never work fine!!

all news articles localized before using this template.

please help me to resolve my problem
thumbnail
Ray Auge, modificado hace 16 años.

RE: How to get articles by locale

Liferay Legend Mensajes: 1197 Fecha de incorporación: 8/02/05 Mensajes recientes
Your code looks good, but you're missing one parameter to the /c/journal/get_articles query:

&amp;language_id=@language_id@


Of course you can hard code the language_id to be 'fa_IR', but '@language_id@' will contain the locale string of the current user.
علي خسروي, modificado hace 16 años.

RE: How to get articles by locale

New Member Mensajes: 3 Fecha de incorporación: 14/01/08 Mensajes recientes
hi Jedi,
thank you for reply. i added @language_id@ before, but did not work.
and in get_articles java source code never use this parameter.


public class GetArticlesAction extends Action {
78  
79      public ActionForward execute(
80              ActionMapping mapping, ActionForm form, HttpServletRequest req,
81              HttpServletResponse res)
82          throws Exception {
83  
84          try {
85              List articles = getArticles(req);
86  
87              String fileName = "articles.xml";
88              byte[] byteArray = getContent(req, articles);
89  
90              ServletResponseUtil.sendFile(
91                  res, fileName, byteArray, Constants.TEXT_XML);
92  
93              return null;
94          }
95          catch (Exception e) {
96              req.setAttribute(PageContext.EXCEPTION, e);
97  
98              return mapping.findForward(Constants.COMMON_ERROR);
99          }
100     }
101 
102     protected List getArticles(HttpServletRequest req) throws Exception {
103         long companyId = PortalUtil.getCompanyId(req);
104         long groupId = DAOParamUtil.getLong(req, "groupId");
105         String articleId = null;
106         Double version = null;
107         String title = null;
108         String description = null;
109         String content = null;
110         String type = DAOParamUtil.getString(req, "type");
111         String structureId = DAOParamUtil.getString(req, "structureId");
112         String templateId = DAOParamUtil.getString(req, "templateId");
113 
114         Date displayDateGT = null;


and in source code use this section to retrieve locale

article.getContentByLocale(themeDisplay.getLanguageId())



is it a bug ? or new feature ?

i use liferay-portal-tomcat-6.0-4.3.5
thumbnail
Ray Auge, modificado hace 16 años.

RE: How to get articles by locale

Liferay Legend Mensajes: 1197 Fecha de incorporación: 8/02/05 Mensajes recientes
It's a bug. I guess someone didn't understand why we needed to be able to override the default Locale obtained from the request through themeDisplay. It's because in Journal, an internal call to /c/journal/get_articles will allways behave as "Guest" and will default to "Guest's" locale.

See http://support.liferay.com/browse/LEP-4773 for the fix. (check commit log)
thumbnail
Filippo Boatto, modificado hace 14 años.

RE: How to get articles by locale

Regular Member Mensajes: 107 Fecha de incorporación: 1/02/07 Mensajes recientes
I have written an article with a structure (checking localized) and a template but


http://10.1.4.191:8082/portal/c/journal/get_articles?groupId=12501&amp;[b]language_id=en_US[/b]&amp;type=marketing&amp;delta=1&amp;approved=true&amp;expired=false&amp;orderBy=display-date


or


http://10.1.4.191:8082/portal/c/journal/get_articles?groupId=12501&amp;[b]language_id=it_IT[/b]&amp;type=marketing&amp;delta=1&amp;approved=true&amp;expired=false&amp;orderBy=display-date


return the same article in the same language why?

I use LR 5.2.3
thumbnail
Filippo Boatto, modificado hace 14 años.

RE: How to get articles by locale - SOLVED

Regular Member Mensajes: 107 Fecha de incorporación: 1/02/07 Mensajes recientes
the parameter to use is:

&amp;[b][color=#00C002]languageId[/color][/b]=@language_id@


and NOT:

&amp;[b][color=#C00300]language_id[/color][/b]=@language_id@



I use this URL

http://@portal_url@/c/journal/get_articles?groupId=@group_id@&amp;[b]languageId=@language_id@[/b]&amp;type=marketing&amp;approved=true&amp;expired=false&amp;delta=1&amp;orderBy=display-date


look at Wiki