enable testing remote locale downloads

This commit is contained in:
Zack Rauen 2019-06-26 22:31:18 -04:00
parent aef6d284aa
commit 2dbd90e0fd
5 changed files with 260 additions and 17 deletions

217
data/locales/en.json Normal file
View File

@ -0,0 +1,217 @@
{
"Panels": {
"plugins": "Plugins",
"themes": "Themes",
"customcss": "Custom CSS"
},
"Collections": {
"settings": {
"name": "Settings",
"general": {
"name": "General",
"emotes": {
"name": "Emote System",
"note": "Enables BD's emote system"
},
"publicServers": {
"name": "Public Servers",
"note": "Display public servers button"
},
"voiceDisconnect": {
"name": "Voice Disconnect",
"note": "Disconnect from voice server when closing Discord"
},
"twentyFourHour": {
"name": "24-Hour Timestamps",
"note": "Hides channels when in minimal mode"
},
"classNormalizer": {
"name": "Normalize Classes",
"note": "Adds stable classes to elements to help themes. (e.g. adds .da-channels to .channels-Ie2l6A)"
},
"showToasts": {
"name": "Show Toasts",
"note": "Shows a small notification for important information"
}
},
"appearance": {
"name": "Appearance",
"voiceMode": {
"name": "Voice Mode",
"note": "Hides everything that isn't voice chat"
},
"minimalMode": {
"name": "Minimal Mode",
"note": "Hide elements and reduce the size of elements"
},
"hideChannels": {
"name": "Hide Channels",
"note": "Hides channels when in minimal mode"
},
"darkMode": {
"name": "Dark Mode",
"note": "Make certain elements dark by default"
},
"coloredText": {
"name": "Colored Text",
"note": "Make text colour the same as role color"
}
},
"addons": {
"name": "Addon Manager",
"addonErrors": {
"name": "Show Addon Errors",
"note": "Shows a modal with plugin/theme errors"
},
"autoScroll": {
"name": "Scroll To Settings",
"note": "Auto-scrolls to a plugin's settings when the button is clicked (only if out of view)"
},
"autoReload": {
"name": "Automatic Loading",
"note": "Automatically loads, reloads, and unloads plugins and themes"
}
},
"customcss": {
"name": "Custom CSS",
"customcss": {
"name": "Custom CSS",
"note": "Enables the Custom CSS tab"
},
"liveUpdate": {
"name": "Live Update",
"note": "Updates the css as you type"
},
"startDetached": {
"name": "Start Detached",
"note": "Clicking the Custom CSS tab opens the editor in a separate window"
},
"nativeOpen": {
"name": "Open in Native Editor",
"note": "Clicking the Custom CSS tab opens your custom css in your native editor"
}
},
"developer": {
"name": "Developer Settings",
"developerMode": {
"name": "Developer Mode",
"note": "Allows activating debugger when pressing F8"
},
"copySelector": {
"name": "Copy Selector",
"note": "Adds a \"Copy Selector\" option to context menus when developer mode is active"
}
},
"window": {
"name": "Window Preferences",
"transparency": {
"name": "Enable Transparency",
"note": "Enables the main window to be see-through (requires restart)"
},
"frame": {
"name": "Window Frame",
"note": "Adds the native os window frame to the main window"
}
}
},
"emotes": {
"name": "Emotes",
"general": {
"name": "General",
"download": {
"name": "Download Emotes",
"note": "Download emotes once a week to stay up to date"
},
"emoteMenu": {
"name": "Emote Menu",
"note": "Show Twitch/Favourite emotes in emote menu"
},
"hideEmojiMenu": {
"name": "Hide Emoji Menu",
"note": "Hides Discord's emoji menu when using emote menu"
},
"autoCaps": {
"name": "Emote Autocapitalization",
"note": "Autocapitalize emote commands"
},
"showNames": {
"name": "Show Names",
"note": "Show emote names on hover"
},
"modifiers": {
"name": "Show Emote Modifiers",
"note": "Enable emote mods (flip, spin, pulse, spin2, spin3, 1spin, 2spin, 3spin, tr, bl, br, shake, shake2, shake3, flap)"
},
"animateOnHover": {
"name": "Animate On Hover",
"note": "Only animate the emote modifiers on hover"
}
},
"categories": {
"name": "Categories",
"twitch": {
"name": "Twitch",
"note": "Show Twitch global & subscriber emotes"
},
"ffz": {
"name": "FrankerFaceZ",
"note": "Show emotes from FFZ"
},
"bttv": {
"name": "BetterTTV",
"note": "Show emotes from BTTV"
}
}
}
},
"Addons": {
"title": "{{name}} v{{version}} by {{author}}",
"openFolder": "Open {{type}} Folder",
"reload": "Reload",
"pluginSettings": "Settings",
"website": "Website",
"source": "Source",
"server": "Support Server",
"donate": "Donate"
},
"Emotes": {
"downloading": "Downloading emotes in the background do not reload.",
"downloaded": "All emotes successfully downloaded.",
"clearEmotes": "Clear Emote Data",
"favoriteAction": "Favorite!"
},
"CustomCSS": {
"confirmationText": "You have unsaved changes to your Custom CSS. Closing this window will lose all those changes.",
"update": "Update",
"save": "Save",
"openNative": "Open in System Editor",
"openDetached": "Detach Window",
"settings": "Editor Settings",
"editorTitle": "Custom CSS Editor"
},
"PublicServers": {
"button": "public",
"join": "Join",
"joining": "Joining",
"joined": "Joined",
"loading": "Loading",
"loadMore": "Load More",
"notConnected": "Not connected to DiscordServers.com!",
"search": "Search",
"connect": "Connect",
"reconnect": "Reconnect",
"categories": "Categories",
"connection": "Connected as: {{username}}#{{discriminator}}",
"results": "Showing {{start}}-{{end}} of {{total}} results in {{category}}",
"query": "for {{query}}"
},
"Modals": {
"confirmClose": "Are You Sure?",
"okay": "Okay",
"cancel": "Cancel",
"name": "Name",
"message": "Message",
"error": "Error",
"addonErrors": "Addon Errors"
}
}

File diff suppressed because one or more lines are too long

View File

@ -35,7 +35,7 @@ Core.prototype.init = async function() {
// `);
// }
DataStore.initialize();
// DataStore.initialize();
ReactComponents.initialize();
Logger.log("Startup", "Initializing Settings");

View File

@ -1,15 +1,10 @@
import {Config} from "data";
import Utilities from "./utilities";
const fs = require("fs");
const path = require("path");
const releaseChannel = DiscordNative.globals.releaseChannel;
// Schema 1
// =======================
// %appdata%\BetterDiscord
// -> data\
// -> [releaseChannel].json (stable/canary/ptb)
// Schema 2
// Schema
// =======================
// %appdata%\BetterDiscord
// -> data
@ -22,11 +17,13 @@ export default new class DataStore {
constructor() {
this.data = {misc: {}};
this.pluginData = {};
this.initialize();
}
initialize() {
if (!fs.existsSync(this.baseFolder)) fs.mkdirSync(this.baseFolder);
if (!fs.existsSync(this.dataFolder)) fs.mkdirSync(this.dataFolder);
if (!fs.existsSync(this.localeFolder)) fs.mkdirSync(this.localeFolder);
if (!fs.existsSync(this.BDFile)) fs.writeFileSync(this.BDFile, JSON.stringify(this.data.misc, null, 4));
if (!fs.existsSync(this.customCSS)) fs.writeFileSync(this.customCSS, "");
const dataFiles = fs.readdirSync(this.dataFolder).filter(f => !fs.statSync(path.resolve(this.dataFolder, f)).isDirectory() && f.endsWith(".json"));
@ -46,6 +43,7 @@ export default new class DataStore {
get customCSS() {return this._customCSS || (this._customCSS = path.resolve(this.dataFolder, "custom.css"));}
get baseFolder() {return this._baseFolder || (this._baseFolder = path.resolve(Config.dataPath, "data"));}
get dataFolder() {return this._dataFolder || (this._dataFolder = path.resolve(this.baseFolder, `${releaseChannel}`));}
get localeFolder() {return this._localeFolder || (this._localeFolder = path.resolve(this.baseFolder, `locales`));}
get BDFile() {return this._BDFile || (this._BDFile = path.resolve(Config.dataPath, "data", `${releaseChannel}.json`));}
// get settingsFile() {return this._settingsFile || (this._settingsFile = path.resolve(Config.dataPath, "bdsettings.json"));}
getPluginFile(pluginName) {return path.resolve(Config.dataPath, "plugins", pluginName + ".config.json");}
@ -73,14 +71,22 @@ export default new class DataStore {
fs.writeFileSync(path.resolve(this.dataFolder, `misc.json`), JSON.stringify(this.data.misc, null, 4));
}
getLocale(locale) {
const file = path.resolve(this.localeFolder, `${locale}.json`);
if (!fs.existsSync(file)) return null;
return Utilities.testJSON(fs.readFileSync(file).toString());
}
saveLocale(locale, strings) {
fs.writeFileSync(path.resolve(this.localeFolder, `${locale}.json`), JSON.stringify(strings, null, 4));
}
getData(key) {
return this.data[key] || "";
// return JSON.parse(fs.readFileSync(path.resolve(this.dataFolder, `${file}.json`)));
}
setData(key, value) {
this.data[key] = value;
// fs.writeFileSync(this.BDFile, JSON.stringify(this.data, null, 4));
fs.writeFileSync(path.resolve(this.dataFolder, `${key}.json`), JSON.stringify(value, null, 4));
}

View File

@ -3,11 +3,30 @@ import RawStrings from "../data/strings";
import Utilities from "./utilities";
import FormattableString from "../structs/string";
import Events from "./emitter";
import DataStore from "./datastore";
const request = require("request");
const discordLocale = UserSettingsStore.locale.split("-")[0];
const savedStrings = DataStore.getLocale(discordLocale);
if (!savedStrings) {
const options = {
url: "https://rauenzi.github.io/BetterDiscordApp/data/emotedata_twitch_subscriber.json",
timeout: 5000,
json: true
};
request.get(options, (err, resp, newStrings) => {
if (err) return;
DataStore.saveLocale(discordLocale, newStrings);
Utilities.extend(Messages, newStrings);
Events.emit("strings-updated");
});
}
const {Dispatcher, DiscordConstants, UserSettingsStore} = DiscordModules;
const Messages = {};
const discordLocale = UserSettingsStore.locale.split("-")[0];
export let currentLocale = "en";
export function setLocale(newLocale) {
@ -18,13 +37,14 @@ export function setLocale(newLocale) {
Utilities.extend(Messages, RawStrings[currentLocale]);
if (RawStrings[discordLocale] && discordLocale != "en") setLocale(discordLocale);
// if (RawStrings[discordLocale] && discordLocale != currentLocale) setLocale(discordLocale);
Dispatcher.subscribe(DiscordConstants.ActionTypes.USER_SETTINGS_UPDATE, ({settings}) => {
const newLocale = settings.locale;
if (newLocale && newLocale != currentLocale) setLocale(newLocale.split("-")[0]);
});
export default new Proxy(Messages, {
get: function(strings, category) {
if (!strings.hasOwnProperty(category)) {