usbong / UsbongKit

A framework for reading and displaying contents of Usbong Trees
www.usbong.ph
Apache License 2.0
2 stars 1 forks source link

How to make Filipino default, and English unlockable? #27

Closed masarapmabuhay closed 7 years ago

masarapmabuhay commented 7 years ago

Salut! I would like to know how to make Filipino the default language, and English unlockable.

I looked at UsbongKit -> Usbong -> UsbongTree -> Defaults.swift

import Foundation

/// Default values
internal struct Defaults {
    static var BaseLanguage = "English"
}

Instead of "English", I replaced it with "Filipino". Unfortunately, this didn't seem to resolve the issue.

Would you be able to teach me how you did it for the "DAHON Nano Course: Financial Independence", where Filipino and Ilonggo come with the app free-of-charge, while English is unlockable?

Merci beaucoup toujours!

chrisamanse commented 7 years ago

IIRC, the "lang" property should be set to the desired default language in the "process-definition" tag of the tree's XML file.

Here's the line that fetches that value: https://github.com/usbong/UsbongKit/blob/master/UsbongKit/Usbong/UsbongTree/UsbongTree.swift#L195

And this is what I meant by "lang" property: https://github.com/usbong/UsbongKit/blob/master/UsbongKit-example/Tree%20Contents/Usbong%20iOS.utree/Usbong%20iOS.xml#L3

Let me know if this works.

chrisamanse commented 7 years ago

Come to think of it, if "lang" is set, there is no need to modify the Defaults struct. (Allowing non-programmers to just modify the XML instead of the code)

masarapmabuhay commented 7 years ago

Salut! Oui, replacing "English" to "Filipino in the lang attribute of the .utree's XML file made "Filipino" the base language. Merci beaucoup!

I attempted to make "English" unlockable by adding it as an item in the LIKHABundles.plist. However, "English" doesn't appear when I do "Set Language" in the Simulator.

Tu sais pourquoi?

masarapmabuhay commented 7 years ago

Salut! Alors, I did the following to get English unlockable. Unfortunately, it would require me to modify the .utree file.

1) Instead of "English", I replaced the BaseLanguage with "Filipino".

import Foundation

/// Default values
internal struct Defaults {
    static var BaseLanguage = "Filipino"
}

2) In my .utree file, I added an English.xml in the trans folder. 3) In my .utree file's XML file, I made "Filipino" the base language. 4) I added English as an item in the LIKHABundles.plist.

Note: I had to put the original content in Step 2 onto Step 3, and the one from Step 3 onto Step 2. This will be quite tedious and labor intensive, since I'll have to redo the entire .utree file.

If you have a much better workaround than this, please do share your insights! S'il te plaît!

In the meantime, I'll see if I can come up with a better solution.

Merci beaucoup!

chrisamanse commented 7 years ago

(1, 2, 3) I was wrong, I did not have to modify anything in the .utree file. Instead, I modified UsbongKit directly and pushed it to the custom-financial-independence branch in UsbongKit: https://github.com/usbong/UsbongKit/tree/custom-financial-independence

The change I made was in TreeViewController.swift of UsbongKit as shown here: https://github.com/usbong/UsbongKit/commit/57d40a9f7fea9c5a6727da16f1ae7f712a58bba0

It may be useful to create an API as suggested in my previous comment: https://github.com/usbong/UsbongKit/issues/6#issuecomment-253459246

let usbongViewer = UsbongViewer(url: treeURL)

usbongViewer.bundles = [] // Pass in In-App Purchase bundles
usbongViewer.defaultBackgroundImage = myImage
usbongViewer.startingLanguage = "Filipino"

usbongViewer.present(on: self)

For now, the simplest workaround would be to modify the TreeViewController.swift in UsbongKit .

(4) Adding English in LIKHABundles.plist is required since it will be an In-App Purchase.

masarapmabuhay commented 7 years ago

D'accord! Let me test out your solution then. Merci bien!

masarapmabuhay commented 7 years ago

Salut! The change that you did in TreeViewController.swift of UsbongKit (57d40a9) resolved the issue.

As for the API, please inform me as soon as it becomes available.

Merci beaucoup!