项目作者: Subnodal

项目描述 :
ARCHIVED! subOS, Subnodal's operating system built for the web.
高级语言: JavaScript
项目地址: git://github.com/Subnodal/os-old.git
创建时间: 2018-12-27T16:35:02Z
项目社区:https://github.com/Subnodal/os-old

开源协议:Other

下载


os

subOS, Subnodal’s operating system built for the web. https://subnodal.com/os

Fun fact: subOS is now over 24,000 source lines of code (sloc) long! With your
contributions, we can make this number rise up and up!

Licence

subOS is licensed by the Subnodal Closed-Source Licence for subOS Front-End.
You may not distribute subOS, as explained in the licence.

Please note: This is only the front-end of subOS, the back-end is completely
closed-source and only accessible by Subnodal employees.

Structure

subOS is run from only one HTML file, index.html.
index.html acts as the screen that is viewed in a browser. There is only one
HTML file so that there isn’t any excessive loading time between screens ─
you only have to load one big file (similar to booting a real computer) which
can go into the browser cache for quicker loading later (that’s if you’re on
the web version, the native version does not take as long to load as the file
is stored locally).

To make it easier for development, the <screen> tag is defined (scripts at
funcs/screens) so
that there is a sense that there are multiple HTML files but really there
isn’t. There is also the benefit of screen transitions too.

Using the <screen> tag

The <screen> tag requires a name attribute and a data-readable tag so
that subReader can tell the user that there was navigation:

  1. <screen name="myScreenName" data-readable="my lovely screen"> ... </screen>

The <screen> tag should also have an info bar (<div class="infoBar">, you
can copy it from another screen and change the buttons, but leave the time in).

To transition to another screen in JavaScript, do either of the following:

  1. // Instantly change screen (generally deprecated; not as friendly)
  2. screens.show("myScreenName");
  3. // Fade into another screen with a time period of 500ms (friendliest)
  4. screens.fade("myScreenName");
  5. // Fade into another screen with a time period (generally deprecated; can be slow)
  6. screens.fade("myScreenName", 1000);

The magical functionality of screens are found at the script at funcs/screens.

Translating subOS

subOS is proud to be multilingual and internationalised/internationalized
(known in the dev world as i18n, localisation/localization is called l12n
to get past the s/z issue. The numbers represent the number of missing
letters)! However i18ning can only be possible with your support, whether it is
from translating the OS into your native language or simply including the @
or _ in your code (see below).

The power of i18n is brought to you by the script at funcs/lang.

i18ning your HTML file

In static HTML elements you can use the @ symbol before strings:

  1. <p>@Some sample text here</p>

If you wish for an element to not be translated, remove the @. If the element
is generated by the user (appended to the DOM) and you don’t want it
translated, put the class noTranslate:

  1. <p class="noTranslate">I was generated by the user!</p>

i18ning your scripts

Your scripts are also easy to i18n. For all strings that you want to translate,
wrap your string like this:

  1. _("Your string will be safe and sound here")

The magic happens with the _ function (it is actually called _ in the
code), an alias for lang.translate. Trust me, you don’t want to write
lang.translate every time you have to translate a string! Use _ instead.

Now what about numbers?! Numbers can’t be translated like this:

  1. _("You got the number " + luckyNumber + "! Congrats!")

You have to do it like this (due to word orders, as well as number formatting):

  1. _("You got the number %! Congrats!", luckyNumber)

The % will be replaced with luckyNumber here. For even more numbers:

  1. _("You got the number %! The number % was also another number.", [luckyNumber, otherNumber])

Don’t forget the list as the second parameter above!

If you want to set some HTML content using JS, construct it like the following:

  1. $(".myDiv").html(`
  2. <span>@You got the lucky number %!|` + luckyNumber + `</span> <a>Something else</a>
  3. `);

For more than one part:

  1. $(".myDiv").html(`
  2. <span>@You got the lucky number %! The number % was also another number.|` + luckyNumber + `,` + otherNumber + `</span> <a>Something else entirely</a>
  3. `);

You should also use the @ in the data-readable attribute too so that they
also get translated.

Making translations for subOS

If you want to translate the text of subOS from English (United Kingdom),
follow this section! Currently there are only 2 languages, English (United
Kingdom) and French (France).

Translations are stored in the lang folder, with the language code
(hyphen-separated) followed by .js as the translation file. It is formatted
like this:

  1. // Language name (Optional language locale name)
  2. lang.list["ln-CD"] = {
  3. "Original en-GB text here blah blah blah": "Translated ln-CD text here blah blah blah",
  4. "Hello, world!": "Canoa, modalo!",
  5. "blah blah blah": "coa coa coa"
  6. "You have got the number %!": "To garo % lo nume!"
  7. ...
  8. };

Where ln-CD is the language code. For plurals, use a JS object instead of a
string:

  1. ...
  2. "You have % new messages": {
  3. sing: "To garo % nen mesolano",
  4. pl: "To garo % nen mesolanos"
  5. }
  6. ...

Oh, and don’t forget to add a <script> tag to index.html to link it correctly!

Lead developers will review your language submission and add the language entry
to language selection menus etc.

Auto-generation

To auto-generate the language file, play around with the OS and open the parts
you want to translate. Then in the developer console, type:

  1. lang.translogToJSObj();

This should return a new language file.

To get more needed translations, type:

  1. lang.translogErrorsToJSSnippet();

This’ll create a snippet that gets the errors and turns them into a snippet
that you can append into the file.

We’ll make the process easier soon! Don’t worry.