-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bundle language support within .app as resources (#3)
* Use Logger * Improve varnam initing * Include VST, VLF in bundle resources * Get list of languages from varnam * Move to schemeID instead of scriptName * Remove dependency on LipikaEngine from IME * Use Logger from Lipika-engine * Close varnam if out of focus, better consistent DB * Add Kannada support * Don't gzip .vlf * Import VLF on postinstall
- Loading branch information
1 parent
db3c62d
commit a06ca8d
Showing
15 changed files
with
515 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "GoVarnam/govarnam"] | ||
path = GoVarnam/govarnam | ||
url = [email protected]:varnamproject/govarnam.git | ||
[submodule "GoVarnam/schemes"] | ||
path = GoVarnam/schemes | ||
url = https://github.com/varnamproject/schemes.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
*.dylib | ||
assets/ | ||
*.vst | ||
*.vlf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import gzip | ||
import json | ||
from os.path import basename | ||
from pathlib import Path | ||
import shutil | ||
from urllib import request | ||
|
||
# Copies .vst, .vlf from schemes folder to assets | ||
# You need to build inside schemes first before running this script | ||
# Use build_all_packs.sh script to do that | ||
|
||
def copyScheme(schemeID): | ||
programDir = str(Path(__file__).parent.absolute()) | ||
source = programDir + '/schemes/schemes/' + schemeID | ||
target = programDir + '/assets' | ||
|
||
packsInfo = [] | ||
|
||
for path in Path(source + '/').rglob('*'): | ||
if basename(path) == schemeID + '.vst': | ||
shutil.copy2(path, target) | ||
continue | ||
|
||
for packPath in Path(path).rglob('*'): | ||
if basename(packPath) == 'pack.json': | ||
packsInfo.append(json.load(open(packPath, 'r'))) | ||
continue | ||
|
||
if ".vlf" not in basename(packPath): | ||
continue | ||
|
||
with open( | ||
packPath, 'rb' | ||
) as f_in, open( | ||
target + '/' + basename(packPath), | ||
'wb' | ||
) as f_out: | ||
f_out.writelines(f_in) | ||
|
||
with open(target + '/packs.json', 'w') as f: | ||
json.dump(packsInfo, f, ensure_ascii=False) | ||
|
||
# For now just Malayalam, Kannada for govarnam-macOS | ||
for schemeID in ["ml", "kn"]: | ||
copyScheme(schemeID) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* LipikaEngine is a multi-codepoint, user-configurable, phonetic, Transliteration Engine. | ||
* Copyright (C) 2017 Ranganath Atreya | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
*/ | ||
|
||
import Foundation | ||
|
||
func synchronize<T>(_ lockObject: AnyObject, _ closure: () -> T) -> T { | ||
objc_sync_enter(lockObject) | ||
defer { objc_sync_exit(lockObject) } | ||
return closure() | ||
} | ||
|
||
func synchronize<T>(_ lockObject: AnyObject, _ closure: () throws -> T) throws -> T { | ||
objc_sync_enter(lockObject) | ||
defer { objc_sync_exit(lockObject) } | ||
return try closure() | ||
} | ||
|
||
let keyBase = Bundle.main.bundleIdentifier ?? "LipikaEngine" | ||
|
||
func getThreadLocalData(key: String) -> Any? { | ||
let fullKey: NSString = "\(keyBase).\(key)" as NSString | ||
return Thread.current.threadDictionary.object(forKey: fullKey) | ||
} | ||
|
||
func setThreadLocalData(key: String, value: Any) { | ||
let fullKey: NSString = "\(keyBase).\(key)" as NSString | ||
Thread.current.threadDictionary.setObject(value, forKey: fullKey) | ||
} | ||
|
||
func removeThreadLocalData(key: String) { | ||
let fullKey: NSString = "\(keyBase).\(key)" as NSString | ||
Thread.current.threadDictionary.removeObject(forKey: fullKey) | ||
} | ||
|
||
func filesInDirectory(directory: URL, withExtension ext: String) throws -> [String] { | ||
let files = try FileManager.default.contentsOfDirectory(at: directory, includingPropertiesForKeys: [], options: []) | ||
return files.filter({$0.pathExtension == ext}).compactMap { $0.deletingPathExtension().lastPathComponent } | ||
} | ||
|
||
extension String { | ||
func unicodeScalars() -> [UnicodeScalar] { | ||
return Array(self.unicodeScalars) | ||
} | ||
|
||
func unicodeScalarReversed() -> String { | ||
var result = "" | ||
result.unicodeScalars.append(contentsOf: self.unicodeScalars.reversed()) | ||
return result | ||
} | ||
|
||
static func + (lhs: String, rhs: [UnicodeScalar]) -> String { | ||
var stringRHS = "" | ||
stringRHS.unicodeScalars.append(contentsOf: rhs) | ||
return lhs + stringRHS | ||
} | ||
} | ||
|
||
// Copyright mxcl, CC-BY-SA 4.0 | ||
// https://stackoverflow.com/a/46354989/1372424 | ||
public extension Array where Element: Hashable { | ||
func uniqued() -> [Element] { | ||
var seen = Set<Element>() | ||
return filter{ seen.insert($0).inserted } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* LipikaEngine is a multi-codepoint, user-configurable, phonetic, Transliteration Engine. | ||
* Copyright (C) 2018 Ranganath Atreya | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
*/ | ||
|
||
import Foundation | ||
|
||
/// This class provides default config values that the client can override, typically using `UserDefaults` and pass an instance into `LiteratorFactory`. | ||
open class Config { | ||
/** | ||
Empty public init to enable clients to call super.init() | ||
*/ | ||
public init() {} | ||
|
||
/** | ||
This character is used to break input aggregation. Typically this is the forward-slash character (`\`). | ||
|
||
__Example__: if `a` maps to `1` and `b` maps to `2` and `ab` maps to `3` then inputting `ab` will output `3` but inputting `a\b` will output `12` | ||
*/ | ||
open var stopCharacter: UnicodeScalar { return "\\" } | ||
|
||
/** | ||
All input characters enclosed by this character will be echoed to the output as-is and not converted. | ||
|
||
__Example__: if `a` maps to `1` and `b` maps to `2` and `ab` maps to `3` then inputting `ab` will output `3` but inputting `` `ab` `` will output `ab` | ||
*/ | ||
open var escapeCharacter: UnicodeScalar { return "`" } | ||
|
||
/** | ||
The URL path to the top-level directory where the schemes files are present. Usually this would return something like `Bundle.main.bundleURL.appendingPathComponent("Mapping")` | ||
*/ | ||
open var mappingDirectory: URL { return Bundle(for: Config.self).bundleURL.appendingPathComponent("Resources", isDirectory: true).appendingPathComponent("Mapping", isDirectory: true) } | ||
|
||
/** | ||
The level at which to NSLog log messages generated by LipikaEngine. | ||
|
||
- Important: This configuration only holds within the same thread in which `LiteratorFactory` was initialized. | ||
*/ | ||
open var logLevel: Logger.Level { return .warning } | ||
} |
Oops, something went wrong.