How to do plugin translations

197 views
Skip to first unread message

ILYA Khlopotov

unread,
Nov 12, 2018, 4:46:48 PM11/12/18
to tiddl...@googlegroups.com
I am completely lost with plugin translations.

The core has `lingo` macro. So I tried to use it as follows:

languages/ru-RU/Note.multids:
```
title: $:/language/plugins/plugin_vendor/plugin_name/

Note: New Note
```

I used it in tiddlers as follows
```
\define lingo-base() $:/language/plugin_vendor/plugin_name/

<<lingo Note>>
```

This seem to work at first. However when I added more translations only one was always selected. The values were overwritten because all translations are mapped to the same tiddler. I found another problem with this approach it didn't work inside widgets. For example following syntax didn't work
```
   <$edit-text
     tiddler="$:/temp/idea"
     field="provisory_title"
     placeholder=<<lingo Note>>
     tag="input" class="tw-edit-texteditor"/>
```

So I came to a conclusion that lingo macro is internal thing which is not supposed to be used in plugins (I could be wrong).

Therefore I need to find another way to achieve my goal (bundle plugin with multiple translations). I think I should rely on the value returned by `$:/language/`, but I don't know how to write a macro which would concatenate the result returned by `$:/language/` with path to namespace of the plugin. I thought to store translation tiddlers under either:
- `$:/language/ru_RU/plugins/plugin_vendor/plugin_name/Note.multids`
- `$:/plugins/plugin_vendor/plugin_name/languages/ru-RU/Note.multids`

Macro is a simple text substitution so it doesn't get the value of `$:/language/`. Do I need:
- a nested transclusion syntax
- use of macrocall
- use set or vars widget

Best regards,
iilyak

ILYA Khlopotov

unread,
Nov 15, 2018, 2:16:20 PM11/15/18
to tiddl...@googlegroups.com
One idea I tried and cannot make it work is

create $:/language/ru-RU/plugins/vendor/name/Note/Text

\define translate(title)
 <$wikify name="location" text="""$:/language/{{{[title{$:/language}removeprefix[$:/languages/]]}}}/plugins/vendor/name/$title$""">
<<location>>
<$wikify>
\end

<<translate Note/Text>>

The generated link to translation tiddler is correct (it opens the right tiddler on click), but I cannot transclude it.

Best regards,
iilyak


TonyM

unread,
Nov 15, 2018, 7:42:55 PM11/15/18
to TiddlyWiki
Ilya,

I would love to help, and would love to know, so I can improve my own solution.

Have you looked in https://tiddlywiki.com/dev/ ?

Regards
Tony

ilya.kh...@gmail.com

unread,
Nov 19, 2018, 9:28:06 PM11/19/18
to TiddlyWiki
One more failed attempt

create $:/languages/ru-RU/plugins/vendor/plugin/Language/Node/Text with translated text

create tiddler to hold translation macro
```
tags: $:/plugins/vendor/plugin/Macros
title: $:/plugins/vendor/plugin/Language
type: text/vnd.tiddlywiki

\define translate(path)
  <$macrocall $name="_translate" language={{$:/language}} path="$path$"/>
\end
\define _translate(language, path)
{{$language$/plugins/vendor/plugin/Language/$path$}}
\end
```

It can be used as
```
<$importvariables filter="[tag[$:/plugins/vendor/plugin/Macros]]">
<<translate Note/Text>>
</$importvariables>
```

Again it cannot be used in widgets. Following will not work
```
<$importvariables filter="[tag[$:/plugins/vendor/plugin/Macros]]">
   <$edit-text
     tiddler="$:/temp/idea"
     field="provisory_title"
     placeholder=<<translate Note>>

     tag="input" class="tw-edit-texteditor"/>
</$importvariables filter="[tag[$:/plugins/vendor/plugin/Macros]]">
```

Best regards,
iilyak

Jeremy Ruston

unread,
Nov 20, 2018, 4:36:35 AM11/20/18
to tiddl...@googlegroups.com
Hi Ilya

I am completely lost with plugin translations.

The core doesn’t currently support translations for plugins, I’m afraid. That doesn’t stop you making a plugin that has multiple translations, but it means that you have to roll your own, including building an equivalent of the `lingo` macro.

Therefore I need to find another way to achieve my goal (bundle plugin with multiple translations). I think I should rely on the value returned by `$:/language/`, but I don't know how to write a macro which would concatenate the result returned by `$:/language/` with path to namespace of the plugin. I thought to store translation tiddlers under either:
- `$:/language/ru_RU/plugins/plugin_vendor/plugin_name/Note.multids`
- `$:/plugins/plugin_vendor/plugin_name/languages/ru-RU/Note.multids`

Here’s one approach:

<$set name="myLingoBase" value={{{ [[$:/plugins/plugin_vendor/plugin_name/]addsuffix{$:/language}]  }}}>

Translated, wikified string: <$transclude tiddler={{{ [<myLingoBase>addsuffix[/MyTranslatedString]] }}}/>

Alternatively, without wikification: <$text text={{{ [<myLingoBase>addsuffix[/MyTranslatedString]get[text]] }}}/>

</$set>

Here we construct a variable “myLingoBase” that will end up containing a string such as "$:/plugins/plugin_vendor/plugin_name/$:/languages/en-GB”. Then when we want to access a particular translatable string we just concatenate the final portion of the tiddler name and transclude it.

Best wishes

Jeremy



Macro is a simple text substitution so it doesn't get the value of `$:/language/`. Do I need:
- a nested transclusion syntax
- use of macrocall
- use set or vars widget

Best regards,
iilyak

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/CAP2DrbT0d1J4kkzzTZ%2BuDUurk4ns4JFAr21VM_Sa2xbozch7RQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Flibbles

unread,
May 12, 2019, 4:21:34 PM5/12/19
to TiddlyWiki
Hi Jeremy,

I'm looking into this too. While your response make good sense to me, I do have one question:

Given the mechanism of the $tw.Language module, and how plugin language translations could theoretically be separate from the plugins they're translating, wouldn't the most appropriate naming convention be:

$:/language/plugin_vendor/plugin_name/...

as opposed to: $:/plugins/plugin_vendor/plugin_name/language/...

I know it doesn't make a difference while plugin translations aren't supported, but I'd hate to have to redo my plugins after the fact, and it seems to me that the plugin translations would likely install in the "<tiddlywiki_dir>/languages". Maybe for example: "<tiddlywiki_dir>/languages/plugin_vendor/plugin_name/fr-FR"

or at least somewhere other than the plugins directory.

Feel free to tell me it doesn't matter. I'm one of those people who's pedantic to sticking to coding conventions perfectly.

Thanks,
-Flibbles





On Tuesday, November 20, 2018 at 4:36:35 AM UTC-5, Jeremy Ruston wrote:
Hi Ilya

I am completely lost with plugin translations.

The core doesn’t currently support translations for plugins, I’m afraid. That doesn’t stop you making a plugin that has multiple translations, but it means that you have to roll your own, including building an equivalent of the `lingo` macro.

Therefore I need to find another way to achieve my goal (bundle plugin with multiple translations). I think I should rely on the value returned by `$:/language/`, but I don't know how to write a macro which would concatenate the result returned by `$:/language/` with path to namespace of the plugin. I thought to store translation tiddlers under either:
- `$:/language/ru_RU/plugins/plugin_vendor/plugin_name/Note.multids`
- `$:/plugins/plugin_vendor/plugin_name/languages/ru-RU/Note.multids`

Here’s one approach:

<$set name="myLingoBase" value={{{ [[$:/plugins/plugin_vendor/plugin_name/]addsuffix{$:/language}]  }}}>

Translated, wikified string: <$transclude tiddler={{{ [<myLingoBase>addsuffix[/MyTranslatedString]] }}}/>

Alternatively, without wikification: <$text text={{{ [<myLingoBase>addsuffix[/MyTranslatedString]get[text]] }}}/>

</$set>

Here we construct a variable “myLingoBase” that will end up containing a string such as "$:/plugins/plugin_vendor/plugin_name/$:/languages/en-GB”. Then when we want to access a particular translatable string we just concatenate the final portion of the tiddler name and transclude it.

Best wishes

Jeremy



Macro is a simple text substitution so it doesn't get the value of `$:/language/`. Do I need:
- a nested transclusion syntax
- use of macrocall
- use set or vars widget

Best regards,
iilyak

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddl...@googlegroups.com.

SylvainComte

unread,
May 13, 2019, 12:44:54 AM5/13/19
to TiddlyWiki
Hello,

You may find this thread on tiddlywikidev useful:

https://groups.google.com/forum/#!topic/tiddlywikidev/fu0QFcs9O_U

Cheers

Sylvain
@sycom

Flibbles

unread,
May 13, 2019, 1:40:43 PM5/13/19
to TiddlyWiki
So that looks like an interesting macro which addresses the problem of localization for now. Except it doesn't seem to answer the question of what the ultimate standard would become. Your macro encourages a "$:/i18n/language/title" naming convention. That means language tiddlers inside my plugin would be named something like:

$:/i18n/en-EN/plugin_vendor/plugin_name/Button/MyButton/Hint

which not only doesn't conform with the $:/plugins/plugin_vendor/plugin_name convention, but steers farther away from what an ultimate convention would be.

Don't get me wrong. Your macro is definitely a solution to the problem. I'm just inquiring about what the ultimate solution will end up becoming.

-Flibbles

SylvainComte

unread,
May 14, 2019, 5:00:44 AM5/14/19
to TiddlyWiki
Hello,

The behaviour is somewhat different with the domain parameter : your translations will be in

domain/i18n/lg-LG

Default value is $:/ but it's up to you and might be $:/plugins/plugin_vendor/plugin_name and your translations will be in

$:/plugins/plugin_vendor/plugin_name/i18n/lg-LG

So it seems there's no conflict with your philosophy. But I guess documentation should be more explicit.

Cheers

Sylvain
@sycom

SylvainComte

unread,
May 14, 2019, 10:49:40 AM5/14/19
to TiddlyWiki
Just to be complete about this, see usage for Feather Icons Plugin, i18n tiddlers are
  • ...
  • $:/plugins/sycom/feather-icons/i18n/en-GB
  • $:/plugins/sycom/feather-icons/i18n/en-GB/macrosIntro
  • $:/plugins/sycom/feather-icons/i18n/en-GB/readme
  • $:/plugins/sycom/feather-icons/i18n/en-GB/usage
  • $:/plugins/sycom/feather-icons/i18n/fr-FR
  • $:/plugins/sycom/feather-icons/i18n/fr-FR/macrosIntro
  • $:/plugins/sycom/feather-icons/i18n/fr-FR/readme
  • $:/plugins/sycom/feather-icons/i18n/fr-FR/usage
  • ...
cheers

Sylvain
@sycom

Flibbles

unread,
May 14, 2019, 2:08:06 PM5/14/19
to TiddlyWiki
All right. So i18n can support whatever domain I configure it to, but then that brings me back to my original question. What would be the most appropriate domain to use.

$:/plugins/vendor_name/plugin_name/...

or

$:/language/vendor_name/plugin_name/...

Convention suggests the first, but the second makes more sense if you consider that plugin translations would be separate from the plugins, and it seems like it may be more appropriate for a final solution.

-Flibbles

Sylvain Comte

unread,
May 14, 2019, 2:43:52 PM5/14/19
to tiddl...@googlegroups.com
Well, the macro was designed to help autonomous translation for devs or users in a easy and clearly distinct way from <<lingo>>. It's transparent for users and doesn't use bundled tiddlers.

I'm a bit agnostic about the best convention to adopt. I'm sure that there would be better advice here around (or on the dev forum)

By the way it's pretty easy to hack the i18n macro to change behaviour. So we just have to decide ;-)

Best regards

Sylvain
@sycom

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/h4UAjwbkdAk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.

To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
Reply all
Reply to author
Forward
0 new messages