Exemple #1
0
Language Language::TryGuessFromFilename(const wxString& filename)
{
    wxFileName fn(filename);
    fn.MakeAbsolute();

    // Try matching the filename first:
    //  - entire name
    //  - suffix (foo.cs_CZ.po, wordpressTheme-cs_CZ.po)
    //  - directory name (cs_CZ, cs.lproj, cs/LC_MESSAGES)
    wxString name = fn.GetName();
    Language lang = Language::TryParseWithValidation(name);
            if (lang.IsValid())
                return lang;

    size_t pos = name.find_first_of(".-_");
    while (pos != wxString::npos)
    {
        auto part = name.substr(pos+1);
        lang = Language::TryParseWithValidation(part);
        if (lang.IsValid())
            return lang;
         pos = name.find_first_of(".-_",  pos+1);
    }

    auto dirs = fn.GetDirs();
    if (!dirs.empty())
    {
        auto d = dirs.rbegin();
        if (d->IsSameAs("LC_MESSAGES", /*caseSensitive=*/false))
        {
            if (++d == dirs.rend())
                return Language(); // failed to match
        }
        wxString rest;
        if (d->EndsWith(".lproj", &rest))
            return Language::TryParseWithValidation(rest);
        else
            return Language::TryParseWithValidation(*d);
    }

    return Language(); // failed to match
}
Exemple #2
0
void PropertiesDialog::TransferFrom(Catalog *cat)
{
    cat->Header().Charset = GetCharsetFromCombobox(m_charset);
    cat->Header().SourceCodeCharset = GetCharsetFromCombobox(m_sourceCodeCharset);

    #define GET_VAL(what,what2) cat->Header().what = m_##what2->GetValue()
    GET_VAL(Team, team);
    GET_VAL(TeamEmail, teamEmail);
    GET_VAL(Project, project);
    GET_VAL(BasePath, basePath);
    #undef GET_VAL

    Language lang = m_language->GetLang();
    if (lang.IsValid())
        cat->Header().Lang = lang;

    wxString dummy;
    wxArrayString arr;

    cat->Header().SearchPaths.Clear();
    cat->Header().Keywords.Clear();

    m_paths->GetStrings(arr);
    for (size_t i = 0; i < arr.GetCount(); i++)
    {
        dummy = arr[i];
        if (dummy[dummy.Length() - 1] == _T('/') || 
                dummy[dummy.Length() - 1] == _T('\\')) 
            dummy.RemoveLast();
        if (!dummy.empty())
            cat->Header().SearchPaths.Add(dummy);
    }
    if (arr.GetCount() > 0 && cat->Header().BasePath.empty()) 
        cat->Header().BasePath = ".";

    m_keywords->GetStrings(arr);
    cat->Header().Keywords = arr;

    wxString pluralForms;
    if (m_pluralFormsDefault->GetValue() && cat->Header().Lang.IsValid())
    {
        pluralForms = cat->Header().Lang.DefaultPluralFormsExpr();
    }

    if (pluralForms.empty())
    {
        pluralForms = m_pluralFormsExpr->GetValue().Strip(wxString::both);
        if ( !pluralForms.empty() && !pluralForms.EndsWith(";") )
            pluralForms += ";";
    }
    cat->Header().SetHeaderNotEmpty("Plural-Forms", pluralForms);
}
Exemple #3
0
void PropertiesDialog::OnPluralFormsDefault(wxCommandEvent& event)
{
    m_rememberedPluralForm = m_pluralFormsExpr->GetValue();

    Language lang = m_language->GetLang();
    if (lang.IsValid())
    {
        wxString defaultForm = lang.DefaultPluralFormsExpr();
        if (!defaultForm.empty())
            m_pluralFormsExpr->SetValue(defaultForm);
    }

    event.Skip();
}
Exemple #4
0
Language Language::TryParseWithValidation(const std::wstring& s)
{
    Language lang = Language::TryParse(s);
    if (!lang.IsValid())
        return Language(); // invalid

    if (!IsISOLanguage(lang.Lang()))
        return Language(); // invalid

    auto country = lang.Country();
    if (!country.empty() && !IsISOCountry(country))
        return Language(); // invalid

    return lang;
}
Exemple #5
0
void PropertiesDialog::TransferFrom(Catalog *cat)
{
    cat->Header().Charset = GetCharsetFromCombobox(m_charset);
    cat->Header().SourceCodeCharset = GetCharsetFromCombobox(m_sourceCodeCharset);

    #define GET_VAL(what,what2) cat->Header().what = m_##what2->GetValue()
    GET_VAL(Team, team);
    GET_VAL(TeamEmail, teamEmail);
    GET_VAL(Project, project);
    GET_VAL(BasePath, basePath);
    #undef GET_VAL

    Language lang = m_language->GetLang();
    if (lang.IsValid())
        cat->Header().Lang = lang;

    GetStringsFromControl(m_keywords, cat->Header().Keywords);
    GetPathsFromControl(m_paths, cat->Header().SearchPaths);
    GetPathsFromControl(m_excludedPaths, cat->Header().SearchPathsExcluded);

    if (!cat->Header().SearchPaths.empty() && cat->Header().BasePath.empty())
        cat->Header().BasePath = ".";

    m_keywords->GetStrings(cat->Header().Keywords);

    wxString pluralForms;
    if (m_pluralFormsDefault->GetValue() && cat->Header().Lang.IsValid())
    {
        pluralForms = cat->Header().Lang.DefaultPluralFormsExpr();
    }

    if (pluralForms.empty())
    {
        pluralForms = m_pluralFormsExpr->GetValue().Strip(wxString::both);
        if ( !pluralForms.empty() && !pluralForms.EndsWith(";") )
            pluralForms += ";";
    }
    cat->Header().SetHeaderNotEmpty("Plural-Forms", pluralForms);
}