Fix gitignore because oops
This commit is contained in:
parent
b3adc08761
commit
d8d9636ab7
|
@ -38,4 +38,5 @@ sysinfo.txt
|
||||||
*.unitypackage
|
*.unitypackage
|
||||||
|
|
||||||
# Hide our localization files with our precious, precious API Keys
|
# Hide our localization files with our precious, precious API Keys
|
||||||
Localization/Editor/
|
Localization/Editor/
|
||||||
|
Assets/Code/Localization/Editor/
|
||||||
|
|
|
@ -1,250 +0,0 @@
|
||||||
using Google.Apis.Auth.OAuth2;
|
|
||||||
using Google.Apis.Sheets.v4;
|
|
||||||
using Google.Apis.Sheets.v4.Data;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using UnityEngine;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
using UnityEditor;
|
|
||||||
|
|
||||||
public static class GoogleSheetsHelper {
|
|
||||||
|
|
||||||
static readonly string JsonLocation = "Assets/Code/Localization/Editor/";
|
|
||||||
static readonly string JsonFile = "clients_secrets.json"; // No use in actual build. This shit has owner permissions.
|
|
||||||
|
|
||||||
static readonly string[] Scopes = { SheetsService.Scope.Spreadsheets };
|
|
||||||
static readonly string ApplicationName = "Localization";
|
|
||||||
static readonly string SpreadsheetId = "1O_Uyml6J_dx7Vt7DLHTTnJqLBXr0ol_xS5pPCjbR1ks";
|
|
||||||
static readonly string cutscenesheet = "mainsheet";
|
|
||||||
static SheetsService service;
|
|
||||||
|
|
||||||
static char LanguageRange = (char)('A' + Localization.LanguageCount);
|
|
||||||
|
|
||||||
static GoogleSheetsHelper() {
|
|
||||||
GoogleCredential credential;
|
|
||||||
using (var stream = new FileStream(System.IO.Path.Combine(JsonLocation, JsonFile), FileMode.Open, FileAccess.Read)) {
|
|
||||||
credential = GoogleCredential.FromStream(stream)
|
|
||||||
.CreateScoped(Scopes);
|
|
||||||
}
|
|
||||||
|
|
||||||
service = new SheetsService(new Google.Apis.Services.BaseClientService.Initializer() {
|
|
||||||
HttpClientInitializer = credential,
|
|
||||||
ApplicationName = ApplicationName
|
|
||||||
}
|
|
||||||
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Push
|
|
||||||
|
|
||||||
public static void Push() {
|
|
||||||
var locals = ReadLocalizaiton();
|
|
||||||
var sheets = ReadGoogleSheets();
|
|
||||||
|
|
||||||
// Create
|
|
||||||
foreach(var item in locals){
|
|
||||||
string[] list;
|
|
||||||
if (!sheets.TryGetValue(item.Key, out list)){
|
|
||||||
list = new string[Localization.LanguageCount];
|
|
||||||
sheets.Add(item.Key, list);
|
|
||||||
}
|
|
||||||
list[0] = item.Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
string message = string.Format("Sending {0} keys.", sheets.Keys.Count);
|
|
||||||
|
|
||||||
if (EditorUtility.DisplayDialog("Confirm Push?", message, "Push", "Do Not Push")) {
|
|
||||||
// Sort
|
|
||||||
var parse = sheets.ToList().Select(s => (s.Key, s.Value)).ToList();
|
|
||||||
parse.Sort((pair1, pair2) => pair1.Key.CompareTo(pair2.Key));
|
|
||||||
|
|
||||||
string prev = string.Empty;
|
|
||||||
for(var i = 0; i < parse.Count; i++){
|
|
||||||
var n = parse[i].Key;
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(n)) continue;
|
|
||||||
|
|
||||||
var t = n.Substring(0, n.IndexOf('_'));
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(prev) && t != prev){
|
|
||||||
parse.Insert(i, (" ", new string[Localization.LanguageCount]));
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
prev = t;
|
|
||||||
}
|
|
||||||
|
|
||||||
SendToGoogleSheets(parse);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Pull(){
|
|
||||||
var sheets = ReadGoogleSheets();
|
|
||||||
|
|
||||||
if (EditorUtility.DisplayDialog("Confirm Pull?", "", "Pull", "Do not Pull")){
|
|
||||||
var serializedObject = new SerializedObject(Localization.Instance);
|
|
||||||
serializedObject.Update();
|
|
||||||
|
|
||||||
var langauges = Localization.Langauges;
|
|
||||||
for (var i = 0; i < langauges.Length; i++){
|
|
||||||
var langauge = (LocalizationLanguage)langauges.GetValue(i);
|
|
||||||
var field = string.Format("{0}Locals", langauge.ToString().ToLowerInvariant());
|
|
||||||
var prop = serializedObject.FindProperty(field);
|
|
||||||
|
|
||||||
var s = 0;
|
|
||||||
foreach(var set in sheets){
|
|
||||||
if (s >= prop.arraySize){
|
|
||||||
prop.InsertArrayElementAtIndex(s);
|
|
||||||
}
|
|
||||||
SerializedProperty element = prop.GetArrayElementAtIndex(s);
|
|
||||||
SerializedProperty keyProp = element.FindPropertyRelative("key");
|
|
||||||
SerializedProperty textProp = element.FindPropertyRelative("text");
|
|
||||||
keyProp.stringValue = set.Key;
|
|
||||||
textProp.stringValue = set.Value[i];
|
|
||||||
s++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
serializedObject.ApplyModifiedProperties();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Assets
|
|
||||||
|
|
||||||
public static Dictionary<string, string> ReadLocalizaiton(){
|
|
||||||
var dict = new Dictionary<string, string>();
|
|
||||||
|
|
||||||
var l = Localization.Instance;
|
|
||||||
|
|
||||||
var locals = l.englishLocals;
|
|
||||||
|
|
||||||
for(var j = 0; j < locals.Length; j++){
|
|
||||||
var item = locals[j];
|
|
||||||
dict.Add(item.key, item.text);
|
|
||||||
}
|
|
||||||
|
|
||||||
return dict;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Google Sheets Read
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns a dictionary of all keys found with their respective localized text.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static Dictionary<string, string[]> ReadGoogleSheets() {
|
|
||||||
var dict = new Dictionary<string, string[]>();
|
|
||||||
|
|
||||||
// Ask google sheets
|
|
||||||
var range = string.Format("{0}!A2:{1}", cutscenesheet, LanguageRange);
|
|
||||||
var request = service.Spreadsheets.Values.Get(SpreadsheetId, range);
|
|
||||||
|
|
||||||
var response = request.Execute();
|
|
||||||
var values = response.Values;
|
|
||||||
|
|
||||||
// If received valid response
|
|
||||||
if (values != null && values.Count > 0) {
|
|
||||||
foreach (var row in values) {
|
|
||||||
if (row.Count > 0) {
|
|
||||||
var key = row[0] as string;
|
|
||||||
if (string.IsNullOrWhiteSpace(key)) continue;
|
|
||||||
|
|
||||||
var list = new string[Localization.LanguageCount];
|
|
||||||
for (var i = 0; i < list.Length; i++){
|
|
||||||
string text;
|
|
||||||
if (i + 1 < row.Count) text = row[i + 1] as string;
|
|
||||||
else text = string.Empty;
|
|
||||||
|
|
||||||
list[i] = text;
|
|
||||||
}
|
|
||||||
|
|
||||||
dict.Add(key, list);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return dict;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Google Sheets Write
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Writes <paramref name="googleLocal"/> to google sheets.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="googleLocal"></param>
|
|
||||||
public static void SendToGoogleSheets(List<(string key, string[] texts)> locals) {
|
|
||||||
var columns = CreateGoogleSheetsColumns(locals);
|
|
||||||
ClearGoogleSheets();
|
|
||||||
WriteToGoogleSheets(columns);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a tabled list to be send with <see cref="WriteToGoogleSheets(List{IList{object}})"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="googleLocal"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static List<IList<object>> CreateGoogleSheetsColumns(List<(string key, string[] texts)> locals) {
|
|
||||||
// Create list to send to google sheets
|
|
||||||
var columns = new List<IList<object>>();
|
|
||||||
|
|
||||||
// Top part with the langauges
|
|
||||||
var header = new List<object>();
|
|
||||||
header.Add("Keys");
|
|
||||||
var langauges = Localization.Langauges;
|
|
||||||
foreach(LocalizationLanguage e in langauges) {
|
|
||||||
header.Add(e.ToString());
|
|
||||||
}
|
|
||||||
columns.Add(header);
|
|
||||||
|
|
||||||
foreach (var pair in locals) {
|
|
||||||
var key = pair.key;
|
|
||||||
var texts = pair.texts;
|
|
||||||
|
|
||||||
var row = new List<object>();
|
|
||||||
row.Add(key);
|
|
||||||
foreach(var t in texts){
|
|
||||||
if (t != null) row.Add(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
columns.Add(row);
|
|
||||||
}
|
|
||||||
|
|
||||||
return columns;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Wipes it clean.
|
|
||||||
/// </summary>
|
|
||||||
public static void ClearGoogleSheets() {
|
|
||||||
var clearRange = new ClearValuesRequest();
|
|
||||||
var clearRequest = service.Spreadsheets.Values.Clear(clearRange, SpreadsheetId, cutscenesheet);
|
|
||||||
var clearReponse = clearRequest.Execute();
|
|
||||||
Debug.Log("Clearing google sheets");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Overwrites the sheet with <paramref name="columns"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="columns"></param>
|
|
||||||
public static void WriteToGoogleSheets(List<IList<object>> columns) {
|
|
||||||
// Create range
|
|
||||||
var range = string.Format("{0}!A1:{1}", cutscenesheet, LanguageRange);
|
|
||||||
var valueRange = new ValueRange();
|
|
||||||
valueRange.Values = columns;
|
|
||||||
|
|
||||||
// Send to Google Sheets
|
|
||||||
var updateRequest = service.Spreadsheets.Values.Update(valueRange, SpreadsheetId, range);
|
|
||||||
updateRequest.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
|
||||||
var updateReponse = updateRequest.Execute();
|
|
||||||
Debug.Log("Finished syncing to google sheets");
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 268efed12188dba47a731c1d552e15cf
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,94 +0,0 @@
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEditor;
|
|
||||||
|
|
||||||
public class LocalizationEditorWindow : EditorWindow {
|
|
||||||
|
|
||||||
[MenuItem("Window/Localization")]
|
|
||||||
static void Init() {
|
|
||||||
var window = EditorWindow.GetWindow<LocalizationEditorWindow>();
|
|
||||||
window.Show();
|
|
||||||
}
|
|
||||||
|
|
||||||
const int heightLimit = 15;
|
|
||||||
|
|
||||||
Localization item;
|
|
||||||
SerializedObject serializedObject;
|
|
||||||
int page = 0;
|
|
||||||
|
|
||||||
private void OnGUI() {
|
|
||||||
GetLocalization();
|
|
||||||
|
|
||||||
var halfwidth = position.width / 2f - 6f;
|
|
||||||
|
|
||||||
serializedObject.Update();
|
|
||||||
|
|
||||||
var englishProp = serializedObject.FindProperty("englishLocals");
|
|
||||||
|
|
||||||
EditorGUILayout.BeginHorizontal();
|
|
||||||
EditorGUILayout.LabelField("Keys", GUILayout.Width(halfwidth));
|
|
||||||
EditorGUILayout.LabelField("Text", GUILayout.Width(halfwidth));
|
|
||||||
EditorGUILayout.EndHorizontal();
|
|
||||||
|
|
||||||
page = Mathf.Clamp(page, 0, englishProp.arraySize / 15);
|
|
||||||
|
|
||||||
var h = 0;
|
|
||||||
var i = page * heightLimit;
|
|
||||||
while(i < englishProp.arraySize && h < heightLimit){
|
|
||||||
var element = englishProp.GetArrayElementAtIndex(i);
|
|
||||||
var key = element.FindPropertyRelative("key");
|
|
||||||
var text = element.FindPropertyRelative("text");
|
|
||||||
|
|
||||||
EditorGUILayout.BeginHorizontal();
|
|
||||||
key.stringValue = EditorGUILayout.TextField(key.stringValue, GUILayout.Width(halfwidth));
|
|
||||||
text.stringValue = EditorGUILayout.TextField(text.stringValue, GUILayout.Width(halfwidth));
|
|
||||||
EditorGUILayout.EndHorizontal();
|
|
||||||
|
|
||||||
i++;
|
|
||||||
h++;
|
|
||||||
}
|
|
||||||
|
|
||||||
EditorGUILayout.BeginHorizontal();
|
|
||||||
GUILayout.FlexibleSpace();
|
|
||||||
if (GUILayout.Button("Prev Page")){
|
|
||||||
page--;
|
|
||||||
GUIUtility.keyboardControl = 0;
|
|
||||||
}
|
|
||||||
GUILayout.Label(string.Format("{0}-{1}", page * heightLimit, Mathf.Min((page + 1) * heightLimit, englishProp.arraySize)));
|
|
||||||
if (GUILayout.Button("Next Page")) {
|
|
||||||
page++;
|
|
||||||
GUIUtility.keyboardControl = 0;
|
|
||||||
}
|
|
||||||
GUILayout.FlexibleSpace();
|
|
||||||
EditorGUILayout.EndHorizontal();
|
|
||||||
|
|
||||||
EditorGUILayout.BeginHorizontal();
|
|
||||||
GUILayout.FlexibleSpace();
|
|
||||||
if (GUILayout.Button("Add key")){
|
|
||||||
englishProp.InsertArrayElementAtIndex(englishProp.arraySize);
|
|
||||||
}
|
|
||||||
GUILayout.FlexibleSpace();
|
|
||||||
EditorGUILayout.EndHorizontal();
|
|
||||||
|
|
||||||
GUILayout.Space(20f);
|
|
||||||
if (GUILayout.Button("Push")){
|
|
||||||
GoogleSheetsHelper.Push();
|
|
||||||
}
|
|
||||||
if (GUILayout.Button("Pull")){
|
|
||||||
GoogleSheetsHelper.Pull();
|
|
||||||
}
|
|
||||||
|
|
||||||
serializedObject.ApplyModifiedProperties();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GetLocalization(){
|
|
||||||
if (item == null) {
|
|
||||||
item = Localization.Instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (serializedObject == null){
|
|
||||||
serializedObject = new SerializedObject(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 1e800b8713d85cc43ba90cb5189fed09
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,12 +0,0 @@
|
||||||
{
|
|
||||||
"type": "service_account",
|
|
||||||
"project_id": "ladyebony-158823",
|
|
||||||
"private_key_id": "0858ab1766408852d7b6b6c48b76870623d52f21",
|
|
||||||
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDBbrE1L7Ja8xnA\n4Vha3Z6K9zdwW+TSNW/Axn31MnL/sti5naqfcqliJf/7phDsiCw+6DSR53Jv0Imu\nIspoEco404pGItATjN3qzt8jU90/Sa7tVob2EPHlXO24w0ney9/+79qjot6mrxhv\nqwfVKfoJDwsgChCnYbdri2TWvOhnZ+Hrf5Qil/+y6TU6kFChFBez2ST4WncokQx7\nP9nRiOMPNIFVn+gLueBvfmqpajWV2IpPk5jUMEwq/nqz+87nUJi67fX9ODb76wzv\n4QHY2pz9ef4Tr78B9Hh5b0R4WeoQ9RPZ+iRpFKdqccPSlcuHqTOm+II3zCqi5pF0\nHVn/FniLAgMBAAECggEAAvWMW0TxVJGqT8uvjCXrZzLXzUc90LcMKgXSjXq9GaS4\nMUOOBaxwybvNFu6rQAMa5WES1M/J1DFIU4d17Nh0Bu4gvzWIu2Cig67jtc8/PKWf\nug/JA5PhleGxduvxG5B0F84kwryBU+MTDtPhMpijmgBGtxgp7KjPcCMmYsaddsXj\na2ll0oaQaE1qDMbL/+z8VIecatfcOdfPovR1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RIVATE KEY-----\n",
|
|
||||||
"client_email": "stationjam@ladyebony-158823.iam.gserviceaccount.com",
|
|
||||||
"client_id": "112738889077453044854",
|
|
||||||
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
|
||||||
"token_uri": "https://oauth2.googleapis.com/token",
|
|
||||||
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
|
||||||
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/stationjam%40ladyebony-158823.iam.gserviceaccount.com"
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: c6876940ea5acb34fad008bc1c07ab95
|
|
||||||
TextScriptImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
Loading…
Reference in New Issue