Skip to content

Commit

Permalink
About panel and l10n checks (#9)
Browse files Browse the repository at this point in the history
* l10n support en+fr

* l10n support en+fr

* added few translations thanks @SzyZuu for German and Polish translations

* l10n'd AboutPanel

* added l10n check

* added AboutPanel translation for French

* added about translation & logo image update

* fix language key

---------

Co-authored-by: serifpersia <ramiserifpersia@gmail.com>
  • Loading branch information
tobozo and serifpersia authored Apr 17, 2024
1 parent d2bc317 commit 76d1dde
Show file tree
Hide file tree
Showing 20 changed files with 275 additions and 92 deletions.
56 changes: 56 additions & 0 deletions .github/scripts/check_l10n.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php




if( !isset($argv) || count($argv)<=1 ) {
phpDie("Usage: php ".__FILE__." /path/to/resources/l10n");
exit(1);
}

$resourceDir = $argv[1];

if( !is_dir($resourceDir) ) {
phpDie( $resourceDir." is not a dir" );
}

if( !file_exists( $resourceDir."/labels.properties")) {
phpDie( $resourceDir." is missing default labels.properties file" );
}

$defaultLang = parse_ini_file($resourceDir."/labels.properties", false, INI_SCANNER_RAW);

//print_r($defaultLang);

if( empty($defaultLang)) {
phpDie( "labels.properties is invalid or empty" );
}

$langFiles = glob($resourceDir."/labels_*");

$errors = 0;

foreach( $langFiles as $langfile ) {
$checkLang = parse_ini_file($langfile, false, INI_SCANNER_RAW);
if( empty($checkLang)) {
echo $langfile." is invalid or empty".PHP_EOL;
$errors++;

}
foreach( $defaultLang as $l10nKey => $l10nval ) {
if( !isset($checkLang[$l10nKey]) || empty($checkLang[$l10nKey]) ) {
echo basename($langfile)." is missing translation for key ".$l10nKey.PHP_EOL;
$errors++;
}
}
}

if( $errors > 0 ) {
phpDie("l10n check failed with ".$errors." errors");
}


function phpDie($msg) {
echo $msg.PHP_EOL;
exit(1);
}
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
java-version: '8'
- name: "Build jar"
run: |
php $GITHUB_WORKSPACE/.github/scripts/check_l10n.php src/main/resources/l10n
[ $? -eq 0 ] || die "Missing translations"
jar_file="build/ESP32PartitionTool.jar"
. $GITHUB_WORKSPACE/.github/scripts/build_jar.sh $jar_file
[ $? -eq 0 ] || die "Jar creation failed"
Expand Down Expand Up @@ -60,4 +62,4 @@ jobs:
with:
files: |
/home/runner/work/esp32partitiontool/esp32partitiontool/archives/**
token: ${{ secrets.RELEASE_TOKEN }} # Use the secret here
token: ${{ secrets.RELEASE_TOKEN }} # Use the secret here
57 changes: 50 additions & 7 deletions src/main/java/com/serifpersia/esp32partitiontool/AboutPanel.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package com.serifpersia.esp32partitiontool;

import javax.swing.*;
import java.awt.Font;
import javax.swing.text.*;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTML.Tag;
import javax.swing.text.html.HTMLEditorKit;
import java.awt.*;

import static javax.swing.text.html.HTML.Tag.IMPLIED;
import static javax.swing.text.html.HTML.Tag.P;


@SuppressWarnings("serial")
Expand All @@ -13,7 +20,10 @@ public AboutPanel() {

private void createPanel() {

setEditable(false);
setEditorKit(new CustomHTMLEditorKit());
setFont( UI.defaultFont.deriveFont(Font.PLAIN, 12) );
setPreferredSize(new Dimension(400, 300));

final String fontFace = "<font face=sans-serif>";
final String boxpadding = "padding-top: 0px;padding-right: 10px;padding-bottom: 10px;padding-left: 10px;";
Expand All @@ -22,13 +32,10 @@ private void createPanel() {
+ "<span style=\"background-color: #42b0f5\">&nbsp;Tool&nbsp;</span>"
+ "<span style=\"background-color: #9a41c2\">&nbsp;v1.4&nbsp;</span>";
final String title = "<h2 align=center style=\"color: #ffffff;\">" + titleSpanned + "</h2>";
final String description = "<p>The ESP32 Partition Tool is a utility designed to ease the manipulation<br>"
+ "of custom partition schemes in the Arduino IDE 1.8.x & PlatformIO environment.<br>"
+ "This tool aims to simplify the process of creating custom partition<br>"
+ "schemes for ESP32 projects.</p>";
final String projectlink = "<p><b>Source:</b><br>https://github.com/serifpersia/esp32partitiontool</p>";
final String description = "<p>"+l10n.getString("aboutPanel.description")+"</p>";
final String projectlink = "<p><b>"+l10n.getString("aboutPanel.source")+":</b><br>https://github.com/serifpersia/esp32partitiontool</p>";
final String copyright = "<p><b>Copyright (c) 2024 @serifpersia</b><br>https://github.com/serifpersia</p>";
final String credits = "<p><b>Contributors:</b><br>serifpersia, tobozo</p>";
final String credits = "<p><b>"+l10n.getString("aboutPanel.contributors")+":</b><br>serifpersia, tobozo, SzyZuu</p>";
final String message = "<html>" + fontFace + title + "<div style=\"" + boxpadding + "\">" + description + projectlink
+ copyright + credits + "</div></html>";

Expand All @@ -38,4 +45,40 @@ private void createPanel() {
setText(message);
}

class CustomHTMLEditorKit extends HTMLEditorKit {

private final ViewFactory viewFactory = new HTMLFactory() {
@Override
public View create(Element elem) {
AttributeSet attrs = elem.getAttributes();
Object elementName = attrs.getAttribute(AbstractDocument.ElementNameAttribute);
Object o = (elementName != null) ? null : attrs.getAttribute(StyleConstants.NameAttribute);
if (o instanceof Tag) {
HTML.Tag kind = (HTML.Tag) o;
if (IMPLIED == kind) return new WrappableParagraphView(elem); // <pre>
if (P == kind) return new WrappableParagraphView(elem); // <p>
}
return super.create(elem);
}
};

@Override
public ViewFactory getViewFactory() {
return this.viewFactory;
}
}

class WrappableParagraphView extends javax.swing.text.html.ParagraphView {

public WrappableParagraphView(Element elem) {
super(elem);
}

@Override
public float getMinimumSpan(int axis) {
return View.X_AXIS == axis ? 0 : super.getMinimumSpan(axis);
}
}


}
9 changes: 7 additions & 2 deletions src/main/java/com/serifpersia/esp32partitiontool/UI.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private Font loadFont(String fontBaseName, int defaultSize, int fallbackType) {
Font matchedFont = Font.createFont(Font.TRUETYPE_FONT, is);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(matchedFont);
System.out.printf("Registered font %s size %d type %d\n", fontBaseName, defaultSize, fallbackType);
//System.out.printf("Registered font %s size %d type %d\n", fontBaseName, defaultSize, fallbackType);
return matchedFont;
} catch (IOException e) {
e.printStackTrace();
Expand Down Expand Up @@ -321,7 +321,12 @@ public JPanel getTitleCSVRow() {
private void createPanels() {

helpPanel = new HelpPanel();
aboutPanel = new AboutPanel();
aboutPanel = new AboutPanel(){
// disallow parent scroll bar pane to use horizontal scrollbar
public boolean getScrollableTracksViewportWidth() {
return true;
}
};
fsPanel = new FSPanel();

fsPanel.setVisible(false);
Expand Down
Loading

0 comments on commit 76d1dde

Please sign in to comment.