SurvivalManual
SurvivalManual copied to clipboard
Default to metric system
Currently imperial and metric system are mixed. I want to change it so the markdown and default is metric and then there is an option to also view it in imperial units ( then parses the text and replaces stuff). Not yet sure if the text should have markup for the places where it needs to replace or if just parsing the plain text.
A short version would be to just add an annex with conversion tables.
That being said, and if this quick way looks good enough, I could work on it.
Not yet sure if the text should have markup for the places where it needs to replace or if just parsing the plain text.
Maybe you could use both. One way to achieve this would be by wrapping the different measures within a tag like <span class="something">n1 X (n2 Y)</span>
where X and Y are the metric and imperial units. In this way, the text remains legible in the wiki but in the application you could get these tags (either through a parser or with a regular expression like <span class="([^"]+)">(.*?)</span>
) keeping only one unit according to the user's settings.
Some examples of how the tags would look inside the text:
<!--- For (almost) all measurements involving centimeters/meters/kilometers or
inches/feet/miles --->
<span class="distance">300 meters (1,000 feet)</span>
<span class="distance">16 to 24 kilometers (10 to 15 miles)</span>
<span class="distance">2.5 to 30 centimeters (1 to 12 inches)</span>
<span class="distance">1 kilometer (1/2 mile)</span>
<span class="distance">3 meters [10 feet]</span>
<span class="distance">1.5 meter (4-foot)</span>
<span class="distance">20-centimeter (8-inch)</span>
<span class="distance">6 millimeters [1/4 inch]</span>
<span class="distance">half meter (18 inches)</span>
<!--- Temperature --->
<span class="temp">60 degrees C (140 degrees F)</span>
<span class="temp">16 to 22 degrees C (30 to 40 degrees F)</span>
<!--- Speed --->
<span class="velocity">112 to 128 kph (67 to 77 mph)</span>
<!--- Weight --->
<span class="weight">19 liters (5 gallons)</span>
<span class="weight">35 kilograms (77 pounds)</span>
<span class="weight">28 milligrams (1 ounce)</span>
Separating the measurements into different "classes" is not strictly necessary, but there may be users who prefer to have the temperature or speed in imperial units and the rest in the metric system. To make the appropiate replacement depending on the configurations, a ~~pseudo~~code like this could be applied:
// Here should be some method to get the user settings
var unitsConfig = mapOf("velocity" to "imperial", "distance" to "metric", "weight" to "metric", "temperature" to "metric")
val measureParser = Regex("""([^\(\[]+)[\[\(]([^\)\]]+)[\]\)]""");
var page = "content of some section app";
var unitsTags = someFunctionToExtractSpanTags(page);
for (tag in unitsTags) {
// Where tag.content is the raw text within the tag and tag.class is the value of the homonymous attribute
var matchResult = measureParser.find(tag.content)
//var (metric, imperial)= matchResult!!.destructured
var dataResult = mapOf("metric" to matchResult!!.groups[1]!!.value.trim(),
"imperial" to matchResult!!.groups[2]!!.value.trim())
page.replace(tag.content, dataResult[unitsConfig[tag.class]])
}
If you implement this, you should keep in mind that the measures will need a consistent format to facilitate their analysis; that is, first the metric measurement and then the imperial between parenthesis or vice versa, but not both, and also that something like "3.2 to 4.8 kilometers per hour (kph) (2 to 3 miles per hour [mph])" would not be recognized by the regular expression or could give errors. It would also be necessary to make a clarification for other editors who want to add content to the wiki in the future.