languages plugin extension

101 views
Skip to first unread message

Grygoriy Fuchedzhy

unread,
May 30, 2011, 10:31:56 AM5/30/11
to hyde...@googlegroups.com
Hello.

I want to extend languages plugin to support all types of files. Because for
example images or videos can contain language specific content. As I can't add
any meta info to files like images the only way to do this is filename
parsing. So dir/en_file.ext is a resource with language: en and uuid: dir/file.ext.

Also I want this plugin to be able to sort files depending on language like
this:

content/
img/
en_pic.jpg
ru_pic.jpg
index.html

transforms into:

deploy/
en/
img/
pic.jpg
ru/
img/
pic.jpg
index.html

I have done that already, and now I want content_url('img/pic.jpg') to return
'en/img/pic.jpg' or 'ru/img/pic.jpg' or 'img/pic.jpg' depending on language of
currently processing file and presense of img/*pic.jpg files in content dir.

I looked at the code of urlcleaner plugin and I can't figure out how to get
currently processing resource from which content_url was called, is it possible?
How can I do that?

Thanks.

--
Grygoriy Fuchedzhy

Vincent Bernat

unread,
May 30, 2011, 4:00:11 PM5/30/11
to hyde...@googlegroups.com
OoO Vers la fin de l'après-midi du lundi 30 mai 2011, vers 16:31,
Grygoriy Fuchedzhy <grygoriy....@gmail.com> disait :

> I looked at the code of urlcleaner plugin and I can't figure out how to get
> currently processing resource from which content_url was called, is it possible?
> How can I do that?

Inside content_url(), you can access self.site.content.resource_from_path().
--
Vincent Bernat ☯ http://www.luffy.cx

panic("Unable to find empty mailbox for aha1542.\n");
2.2.16 /usr/src/linux/drivers/scsi/aha1542.c

Grygoriy Fuchedzhy

unread,
May 30, 2011, 4:17:14 PM5/30/11
to hyde...@googlegroups.com
On Mon, May 30, 2011 at 10:00:11PM +0200, Vincent Bernat wrote:
> Inside content_url(), you can access self.site.content.resource_from_path().

That will not help, I need to get language of currently processing file from
content_url function, I mean file that contains {{content_url('somefile')}}. I
don't know its path.

--
Grygoriy Fuchedzhy

Vincent Bernat

unread,
May 30, 2011, 4:24:04 PM5/30/11
to hyde...@googlegroups.com
OoO En cette soirée bien amorcée du lundi 30 mai 2011, vers 22:17,
Grygoriy Fuchedzhy <grygoriy....@gmail.com> disait :

>> Inside content_url(), you can access self.site.content.resource_from_path().

> That will not help, I need to get language of currently processing file from
> content_url function, I mean file that contains {{content_url('somefile')}}. I
> don't know its path.

Oh, OK, I misunderstood the question. Sorry, I don't know the answer.


--
Vincent Bernat ☯ http://www.luffy.cx

Use data arrays to avoid repetitive control sequences.
- The Elements of Programming Style (Kernighan & Plauger)

Grygoriy Fuchedzhy

unread,
Jun 6, 2011, 8:01:40 AM6/6/11
to hyde...@googlegroups.com
> How to get

> currently processing resource from which content_url was called, is it possible?
> How can I do that?

It seems that it is currently impossible to do so. Because
ext.templates.jinja.media_url and ext.templates.jinja.content_url calls
Site.media_url and Site.content_url functions.

I think that modifying ext.templates.jinja.*_url functions and moving media_url,
content_url functions from Site to Resource would be right thing to do as
Resource object in *_url functions may be more useful then Site object for
plugins which will decide to override them like urlcleaner plugin does.

Also it seems that its easy to do.

What do you think?

--
Grygoriy Fuchedzhy

Grygoriy Fuchedzhy

unread,
Jun 6, 2011, 8:56:29 AM6/6/11
to hyde...@googlegroups.com
I have also one more suggestion: it would be convenient to be able to refer to
other files relatively, maybe via separate function, e.g. if we have following
structure:

content/
dir1/
dir2/
dir3/
index.html
photo1.jpg
photo2.jpg

It would be convenient to write something like this in index.html:
{{rel_media_url('photo1.jpg')}}
instead of
{{media_url('dir1/dir2/dir3/photo1.jpg')}}

--
Grygoriy Fuchedzhy

Lakshmi

unread,
Jun 19, 2011, 1:18:29 AM6/19/11
to hyde...@googlegroups.com
I am wondering if translation / language should be added to hyde core to solve problems like this. 

For example, allowing content_url to accept language as a parameter.

Will give it more thought this weekend and respond on Monday.

Lakshmi

unread,
Jun 19, 2011, 1:20:40 AM6/19/11
to hyde...@googlegroups.com
Not sure if moving it to resource would solve the problem completely - what if you need the content url of a resource in language x.

Lakshmi

unread,
Jun 19, 2011, 1:22:41 AM6/19/11
to hyde...@googlegroups.com
So, the idea is:

* The rel_x_url function accepts a path
* The path must be unique
* We find the resource by searching for the path under "x" (media or content)
* Provide the expanded relative path

Is that right?



Grygoriy Fuchedzhy

unread,
Jun 19, 2011, 4:28:46 AM6/19/11
to hyde...@googlegroups.com

I think extra detailed example will explain it clearer.
dir1/
dir2/
1.html
other_page.html
dir3/
2.html
other_page.html
media/
dir1/
dir2/
pic.jpg
dir3/
pic.jpg

Both 1.html and 2.html contain rel_content_url('other_page.html') and
rel_media_url('pic.jpg') which expands to different things:

/dir1/dir2/other_page.html and /media/dir1/dir2/pic.jpg for 1.html
/dir1/dir3/other_page.html and /media/dir1/dir3/pic.jpg for 2.html

So rel_content_url(path) searches for path under current node, in this example
under /dir1/dir2/ or /dir1/dir3/. rel_media_url(path) searches for path under
corresponding node in media dir, in this example under /media/dir1/dir2/ of
/media/dir1/dir3/

On Sat, Jun 18, 2011 at 10:20:40PM -0700, Lakshmi wrote:
> Not sure if moving it to resource would solve the problem completely - what
> if you need the content url of a resource in language x.

So probably *_url functions need optional language parameter which defaults to
language of currently processing resource (resource from which *_url was
called).

However, I think moving *_url functions to resource would be useful
anyway. Because some other plugin may need currently processing resource to get
some other parameter.

--
Grygoriy Fuchedzhy

Lakshmi Vyas

unread,
Jun 19, 2011, 5:11:30 AM6/19/11
to hyde...@googlegroups.com
Ah, I see. Makes sense. Will add it to the issues list.

> --
> You received this message because you are subscribed to the Google Groups "Hyde" group.
> To post to this group, send email to hyde...@googlegroups.com.
> To unsubscribe from this group, send email to hyde-dev+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/hyde-dev?hl=en.
>

Reply all
Reply to author
Forward
0 new messages