============================================================
--- lib/samizdat/components/resource.rb 6c25f845f001fbff129d352978cc840dcaeecfcc
+++ lib/samizdat/components/resource.rb a02f94447fac7881cc95ee0e8e737a8a37519f28
@@ -248,7 +248,12 @@ ORDER BY ?msg}, limit_page, limit_page *
(s::hidden ?msg ?hidden)
LITERAL ?msg IS NOT NULL #{exclude_hidden}
ORDER BY ?msg}, limit_page, limit_page * skip
- ).collect {|reply,| Resource.new(@request, reply).short }
+ ).collect {|reply,|
+ # don't include translations in replies
+ # translations is [ [l, m, r], ... ]
+ @message.translations.rassoc(reply) ?
+ nil : Resource.new(@request, reply).short
+ }.compact
box(
_('Replies') + (skip > 0? sprintf(_(', page %s'), skip + 1) : ''),
============================================================
--- lib/samizdat/helpers/message_helper.rb 018de7853f0d3db9a99eb9c5d3fcbc37ff993227
+++ lib/samizdat/helpers/message_helper.rb eda04099b7c9b4edc0412ca38ea9213477b1c9bd
@@ -57,13 +57,21 @@ module MessageHelper
replies = %{} + _('replies') +
': ' + message.nreplies.to_s if message.nreplies.to_i > 0
+
+ # optimize: don't run select_translation twice here and in message()
+ translation = message.select_translation(@request.accept_language)
translations = _('translation') + ': ' +
message.translations.sort_by {|l,m,r| -r.to_f }.collect {|l,m,r|
+ if translation and translation.id == m
+ l = message.lang # swap preferred translation and original
+ end
%{#{l}}
}.join(' ') if message.translations.to_a.size > 0
+
focuses = focus_line(message.id, message.focuses.collect {|f|
Focus.new(@request, f, message.id)
})
+
hidden = _('hidden') if message.hidden?
[ sprintf(_('by %s on %s'), creator, date.to_s),
@@ -128,8 +136,11 @@ module MessageHelper
if not message.version_of # no buttons for old versions
if @request.access('post')
- # todo: don't allow to post replies to focuses
- buttons << message_button(message.id, 'reply', _('Reply'))
+ unless message.is_translation?
+ # don't allow to post replies to translations
+ # todo: don't allow to post replies to focuses
+ buttons << message_button(message.id, 'reply', _('Reply'))
+ end
open =
if @session.member.nil? # guest
@@ -173,31 +184,33 @@ module MessageHelper
#
def message(message, mode)
info = message_info(message, mode)
- # use translation in :short mode
- translation = (:short == mode)?
- message.select_translation(@request.accept_language) : message
- if :full != mode # title is already in the page head in :full mode
+
+ translation = (:preview == mode) ?
+ message :
+ message.select_translation(@request.accept_language)
+
+ if :short == mode # title is already in the page head in :full mode
title = translation.content.title
title = Focus.focus_title(title) if
:short == mode and message.nrelated > 0
title = CGI.escapeHTML(limit_string(title))
title = %{
#{resource_href(message.id, title)}
\n}
end
+
if translation.desc and translation.desc != translation.id
# use description of translation when applicable
desc = message_content(Message.cached(translation.desc), :short)
end
- content =
- if desc
- if :short == mode
- desc + full_message_href(message.id)
- else
- box(resource_href(message.desc, _('Description')), desc, 'desc') +
- message_content(message, mode)
- end
- else
- message_content(translation, mode)
+ if desc and :short == mode
+ content = desc + full_message_href(message.id)
+ else
+ content = ''
+ if desc # prepend content with description box
+ content << box(resource_href(message.desc, _('Description')), desc, 'desc')
end
+ content << message_content(translation, mode)
+ end
+
html =
%{
#{title}
#{info}
============================================================
--- lib/samizdat/models/focus.rb b64306a952a5071a2adb138baebe0d145f8163ef
+++ lib/samizdat/models/focus.rb 3d540227cd8478aec2b1ad957fdf5ce804f39ba7
@@ -84,6 +84,15 @@ ORDER BY count(?resource) DESC}, limit_p
list.collect {|focus, usage| yield focus, usage }
end
+ # retrieve and cache id of the focus::Translation resource
+ #
+ def Focus.translation_focus
+ cache.fetch_or_add('translation_focus') do
+ id, = rdf.select_one('SELECT ?id WHERE (s::id focus::Translation ?id)')
+ id
+ end
+ end
+
# read and cache rating from SamizdatRDF
#
def rating
============================================================
--- lib/samizdat/models/message.rb 45276eecbdef6d4c5008f23818ce6f8fba906532
+++ lib/samizdat/models/message.rb 55fc0a1489fc8752eb6a0f975b3e86ff56576f5d
@@ -51,7 +51,7 @@ LITERAL ?rating > 0 #{exclude_hidden}
(s::rating ?stmt ?rating)
(s::hidden ?msg ?hidden)
LITERAL ?rating > 0 #{exclude_hidden}
-ORDER BY ?rating DESC}, limit_page).collect {|m, l, r| [m, l, r] } # DBI::Row
+ORDER BY ?rating DESC}, limit_page).collect {|l, m, r| [l, m, r] } # DBI::Row to Array
@nreplies, = rdf.select_one %{
SELECT count(?msg)
WHERE (s::inReplyTo ?msg address@hidden)
@@ -154,19 +154,33 @@ LITERAL ?rating > 0})
end
end
+ def is_translation?
+ @parent and @focuses.include?(Focus.translation_focus)
+ end
+
# find available translation to the most preferred language
#
# returns Message object or self, when no translation is suitable
#
def select_translation(accept_language)
return self unless @lang # don't translate messages with no language
- t_id = nil # translation id
+
+ if is_translation?
+ parent = Message.cached(@parent)
+ pt = parent.select_translation(accept_language)
+ if pt.id == @id
+ # if I'm the parent's preferred translation, swap us
+ return parent
+ end
+ end
+
+ t_row = nil
accept_language.each do |l|
break if l == @lang # message already in preferred language
- t_id = @translations.assoc(l)
- break unless t_id.nil?
+ t_row = @translations.assoc(l)
+ break unless t_row.nil?
end
- t_id ? Message.cached(t_id[1]) : self
+ t_row ? Message.cached(t_row[1]) : self
end
# fixme: refactor it out to MessageHelper