mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-23 07:26:54 +00:00
First pass at language plugins for internationalisation
Still quite a few details to work out, but this shows the basic idea of re-using the theme mechanism to handle language plugins. Comments and questions welcome.
This commit is contained in:
parent
d1bc053a9c
commit
dea08ed4f8
29
boot/boot.js
29
boot/boot.js
@ -1291,6 +1291,9 @@ $tw.boot.defaultWikiInfo = {
|
||||
"themes": [
|
||||
"tiddlywiki/vanilla",
|
||||
"tiddlywiki/snowwhite"
|
||||
],
|
||||
"languages": [
|
||||
"en-GB"
|
||||
]
|
||||
};
|
||||
|
||||
@ -1342,6 +1345,16 @@ $tw.loadWikiTiddlers = function(wikiPath,parentPaths) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Load any languages listed in the wiki info file
|
||||
if(wikiInfo.languages) {
|
||||
var languagesBasePath = path.resolve($tw.boot.corePath,$tw.config.languagesPath);
|
||||
for(var t=0; t<wikiInfo.languages.length; t++) {
|
||||
pluginFields = $tw.loadPluginFolder(path.resolve(languagesBasePath,"./" + wikiInfo.languages[t]));
|
||||
if(pluginFields) {
|
||||
$tw.wiki.addTiddler(pluginFields);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Load the wiki files, registering them as writable
|
||||
var resolvedWikiPath = path.resolve(wikiPath,$tw.config.wikiTiddlersSubDir);
|
||||
$tw.utils.each($tw.loadTiddlersFromPath(resolvedWikiPath),function(tiddlerFile) {
|
||||
@ -1380,6 +1393,17 @@ $tw.loadWikiTiddlers = function(wikiPath,parentPaths) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Load any languages within the wiki folder
|
||||
var wikiLanguagesPath = path.resolve(wikiPath,$tw.config.wikiLanguagesSubDir);
|
||||
if(fs.existsSync(wikiLanguagesPath)) {
|
||||
var languageFolders = fs.readdirSync(wikiLanguagesPath);
|
||||
for(t=0; t<languageFolders.length; t++) {
|
||||
pluginFields = $tw.loadPluginFolder(path.resolve(wikiLanguagesPath,"./" + languageFolders[t]));
|
||||
if(pluginFields) {
|
||||
$tw.wiki.addTiddler(pluginFields);
|
||||
}
|
||||
}
|
||||
}
|
||||
return wikiInfo;
|
||||
};
|
||||
|
||||
@ -1416,9 +1440,11 @@ $tw.boot.startup = function(options) {
|
||||
config: { // Configuration overridables
|
||||
pluginsPath: "../plugins/",
|
||||
themesPath: "../themes/",
|
||||
languagesPath: "../languages/",
|
||||
wikiInfo: "./tiddlywiki.info",
|
||||
wikiPluginsSubDir: "./plugins",
|
||||
wikiThemesSubDir: "./themes",
|
||||
wikiLanguagesSubDir: "./languages",
|
||||
wikiTiddlersSubDir: "./tiddlers",
|
||||
jsModuleHeaderRegExpString: "^\\/\\*\\\\(?:\\r?\\n)((?:^[^\\r\\n]*(?:\\r?\\n))+?)(^\\\\\\*\\/$(?:\\r?\\n)?)",
|
||||
fileExtensionInfo: {}, // Map file extension to {type:}
|
||||
@ -1532,6 +1558,3 @@ if(typeof(exports) !== "undefined") {
|
||||
} else {
|
||||
_boot(window.$tw);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -38,6 +38,15 @@ exports.startup = function() {
|
||||
$tw.syncer = new $tw.Syncer({wiki: $tw.wiki});
|
||||
// Set up the command modules
|
||||
$tw.Commander.initCommands();
|
||||
// Kick off the language manager
|
||||
$tw.languageManager = new $tw.PluginSwitcher({
|
||||
wiki: $tw.wiki,
|
||||
pluginType: "language",
|
||||
controllerTitle: "$:/language",
|
||||
defaultPlugins: [
|
||||
"$:/languages/en-US"
|
||||
]
|
||||
});
|
||||
// Kick off the theme manager
|
||||
$tw.themeManager = new $tw.PluginSwitcher({
|
||||
wiki: $tw.wiki,
|
||||
|
@ -8,6 +8,7 @@ caption: Basics
|
||||
|[[Username for signing edits|$:/status/UserName]] |<$edit-text tiddler="$:/status/UserName" default="" tag="input"/> |
|
||||
|[[Animation duration|$:/config/AnimationDuration]] |<$edit-text tiddler="$:/config/AnimationDuration" default="" tag="input"/> |
|
||||
|[[DefaultTiddlers|$:/DefaultTiddlers]] |Choose which tiddlers are displayed at startup:<br> <$edit-text tag="textarea" tiddler="$:/DefaultTiddlers"/><br>//Use [[double square brackets]] for titles with spaces. Or you can choose to <$button set="$:/DefaultTiddlers" setTo="[list[$:/StoryList]]">retain story ordering</$button>// |
|
||||
|{{$:/lingo/ControlPanel/Language/prompt}} |{{$:/snippets/minilanguageswitcher}} |
|
||||
|Tiddlers |''<$count filter="[!is[system]]"/>'' |
|
||||
|Tags |''<$count filter="[tags[]]"/>'' |
|
||||
|System tiddlers |''<$count filter="[is[system]]"/>'' |
|
||||
|
@ -2,18 +2,6 @@ title: $:/core/ui/SideBar/Tools
|
||||
tags: $:/tags/SideBar
|
||||
caption: Tools
|
||||
|
||||
{{$:/snippets/viewswitcher}}
|
||||
|
||||
---
|
||||
|
||||
[[AdvancedSearch|$:/AdvancedSearch]]
|
||||
|
||||
---
|
||||
|
||||
{{$:/snippets/minithemeswitcher}}
|
||||
|
||||
---
|
||||
|
||||
Import: <$browse/>
|
||||
|
||||
---
|
||||
@ -23,3 +11,15 @@ Import: <$browse/>
|
||||
---
|
||||
|
||||
TiddlyWiki5 version <<version>>
|
||||
|
||||
---
|
||||
|
||||
{{$:/snippets/viewswitcher}}
|
||||
|
||||
---
|
||||
|
||||
{{$:/snippets/minithemeswitcher}}
|
||||
|
||||
---
|
||||
|
||||
{{$:/snippets/languageswitcher}}
|
||||
|
8
core/wiki/languageswitcher.tid
Normal file
8
core/wiki/languageswitcher.tid
Normal file
@ -0,0 +1,8 @@
|
||||
title: $:/snippets/languageswitcher
|
||||
|
||||
{{$:/lingo/ControlPanel/Language/prompt}} <$view tiddler={{$:/language}} field="description" format="text"><$view tiddler={{$:/language}} field="name" format="text"><$view tiddler={{$:/language}} field="title" format="text"/></$view></$view>
|
||||
|
||||
<$linkcatcher to="$:/language">
|
||||
<$list filter="[plugin-type[language]sort[title]]"><div><$reveal state="$:/language" type="match" text={{!!title}}>•</$reveal><$reveal state="$:/language" type="nomatch" text={{!!title}}> </$reveal> <$link to={{!!title}}><$view field="description" format="text"><$view field="name" format="text"><$view field="title" format="text"/></$view></$view></$link></div>
|
||||
</$list>
|
||||
</$linkcatcher>
|
6
core/wiki/minilanguageswitcher.tid
Normal file
6
core/wiki/minilanguageswitcher.tid
Normal file
@ -0,0 +1,6 @@
|
||||
title: $:/snippets/minilanguageswitcher
|
||||
|
||||
<$linkcatcher to="$:/language">
|
||||
<$list filter="[plugin-type[language]sort[title]]"><div><$reveal state="$:/language" type="match" text={{!!title}}>•</$reveal><$reveal state="$:/language" type="nomatch" text={{!!title}}> </$reveal> <$link to={{!!title}}><$view field="description" format="text"><$view field="name" format="text"><$view field="title" format="text"/></$view></$view></$link></div>
|
||||
</$list>
|
||||
</$linkcatcher>
|
3
editions/tw5.com/tiddlers/system/language.tid
Normal file
3
editions/tw5.com/tiddlers/system/language.tid
Normal file
@ -0,0 +1,3 @@
|
||||
title: $:/language
|
||||
|
||||
$:/languages/en-GB
|
@ -16,5 +16,11 @@
|
||||
"giffmex/rocker",
|
||||
"giffmex/blue",
|
||||
"giffmex/blanca"
|
||||
],
|
||||
"languages": [
|
||||
"en-US",
|
||||
"en-GB",
|
||||
"de-AT",
|
||||
"fr-FR"
|
||||
]
|
||||
}
|
3
languages/de-AT/languageprompt.tid
Normal file
3
languages/de-AT/languageprompt.tid
Normal file
@ -0,0 +1,3 @@
|
||||
title: $:/lingo/ControlPanel/Language/prompt
|
||||
|
||||
Hallo! Aktuelle Sprache:
|
8
languages/de-AT/plugin.info
Normal file
8
languages/de-AT/plugin.info
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"title": "$:/languages/de-AT",
|
||||
"name": "de-AT",
|
||||
"plugin-type": "language",
|
||||
"description": "German (Austria)",
|
||||
"author": "JeremyRuston",
|
||||
"core-version": ">=5.0.0"
|
||||
}
|
3
languages/en-GB/languageprompt.tid
Normal file
3
languages/en-GB/languageprompt.tid
Normal file
@ -0,0 +1,3 @@
|
||||
title: $:/lingo/ControlPanel/Language/prompt
|
||||
|
||||
Hello! Current language:
|
8
languages/en-GB/plugin.info
Normal file
8
languages/en-GB/plugin.info
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"title": "$:/languages/en-GB",
|
||||
"name": "en-GB",
|
||||
"plugin-type": "language",
|
||||
"description": "English (British)",
|
||||
"author": "JeremyRuston",
|
||||
"core-version": ">=5.0.0"
|
||||
}
|
3
languages/en-US/languageprompt.tid
Normal file
3
languages/en-US/languageprompt.tid
Normal file
@ -0,0 +1,3 @@
|
||||
title: $:/lingo/ControlPanel/Language/prompt
|
||||
|
||||
Hiya! Current language:
|
9
languages/en-US/plugin.info
Normal file
9
languages/en-US/plugin.info
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"title": "$:/languages/en-US",
|
||||
"name": "en-US",
|
||||
"plugin-type": "language",
|
||||
"description": "English (US)",
|
||||
"author": "JeremyRuston",
|
||||
"core-version": ">=5.0.0",
|
||||
"dependents": ["$:/languages/en-GB"]
|
||||
}
|
3
languages/fr-FR/languageprompt.tid
Normal file
3
languages/fr-FR/languageprompt.tid
Normal file
@ -0,0 +1,3 @@
|
||||
title: $:/lingo/ControlPanel/Language/prompt
|
||||
|
||||
Bonjour! Langage courant:
|
8
languages/fr-FR/plugin.info
Normal file
8
languages/fr-FR/plugin.info
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"title": "$:/languages/fr-FR",
|
||||
"name": "fr-FR",
|
||||
"plugin-type": "language",
|
||||
"description": "French (France)",
|
||||
"author": "JeremyRuston",
|
||||
"core-version": ">=5.0.0"
|
||||
}
|
Loading…
Reference in New Issue
Block a user