/usr/share/oolite/Scripts/oolite-locale-functions.js is in oolite-data 1.77.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | /*
oolite-locale-functions.js
This script implements certain functionality that may need to be modified when
localizing Oolite, such as number formatting. It’s intended to be overridden
by localization OXPs, and is loaded after oolite-global-prefix.js but before
any “normal” world scripts.
Oolite
Copyright © 2004-2013 Giles C Williams and contributors
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
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. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
*/
"use strict";
this.name = "oolite-locale-functions";
this.author = "Jens Ayton";
this.copyright = "© 2012-2013 the Oolite team.";
this.version = "1.77.1";
(function () {
// Simple parameters. For more complex behaviour change, modify the functions that do the work.
const minSepDigits = +expandDescription("[number-group-threshold]");
const groupSize = +expandDescription("[number-group-size]");
const maxTotalDigits = 16; // This is near the limit of numerical precision.
const maxIntegerValue = Math.pow(10, maxTotalDigits);
const radix = expandDescription("[number-decimal-separator]");
const groupSep = expandDescription("[number-group-separator]");
const currencyFormat = expandDescription("[@-credits]");
// Utility to define non-enumerable, non-configurable, permanent methods, to match the behaviour of native methods.
// FIXME: not used because global properties are not reset when resetting game.
function defineMethod(object, name, implementation)
{
Object.defineProperty(object, name, { value: implementation, writable: false, configurable: false, enumerable: false });
}
// Internal method returns a pair [result, isScientificNotation] for the benefit of format[Deci]Credits.
function formatPositiveIntegerInternal (value)
{
if (value > maxIntegerValue) return [formatScientificInternal(value), true];
var digits = value.toString();
var digitCount = digits.length;
if (digitCount >= minSepDigits)
{
if (digitCount > maxTotalDigits) return [formatScientificInternal(value), true];
var result = "";
var empty = true;
while (digitCount > groupSize)
{
digitCount -= groupSize;
var group = digits.substr(digitCount, groupSize);
if (empty)
{
result = group;
empty = false;
}
else
{
result = group.concat(groupSep, result);
}
}
if (digitCount > 0)
{
result = digits.substr(0, digitCount).concat(groupSep, result);
}
}
else
{
var result = digits;
}
return [result, false];
}
function formatScientificInternal(value)
{
return value.toString();
}
global.formatInteger = function formatInteger(value)
{
var value = Math.round(+value);
var negative = false;
if (value < 0)
{
negative = true;
value = -value;
}
var string = formatPositiveIntegerInternal(value)[0];
if (negative) string = "-" + string;
return string;
}
global.formatCredits = function formatCredits(value, includeDeciCredits, includeCurrencySymbol)
{
var negative = false;
if (value < 0)
{
negative = true;
value = -value;
}
value += (includeDeciCredits ? 0.05 : 0.5);
var floor = Math.floor(value);
var [string, isSciNotation] = formatPositiveIntegerInternal(floor);
if (includeDeciCredits && !isSciNotation)
{
var frac = Math.floor(((value - floor) * 10));
string = string.concat(radix, frac.toString());
}
if (includeCurrencySymbol)
{
string = currencyFormat.replace("%@", string);
}
if (negative) string = "-" + string;
return string;
}
})();
|